Load stopwords.words('english') null

25 views
Skip to first unread message

Thien Vu Trong

unread,
Oct 16, 2017, 12:43:38 PM10/16/17
to nltk-users
Hi all,

I am beginner, I have just write a program that use nltk library.
In that program I use stopwords, and get it by command "stopwords.words('english')"

I run on linux Redhat 7.
When I call python from terminal, it is ok. (get stopwords ok)
But when I call python script from php (run on NGINX), that command (stopwords.words('english') not work. (use: exec, shell_exec, passthru)

Please help me to solve this problem.
Thanks, 
My simple program like this:

import sys
from nltk.corpus import stopwords
try:
print(123)
    # this not work when call python program from php (use: exec, shell_exec, passthru)
stops = set(stopwords.words('english'))
print(234)
except Exception as e:
print(e)
print(stops)
sys.exit(0)

Dimitriadis, A. (Alexis)

unread,
Oct 16, 2017, 6:38:20 PM10/16/17
to nltk-...@googlegroups.com
Sorry but it’s very hard to imagine what might have gone wrong. To get help, you’ll need to provide more information about the problem. What error message do you get when the program “does not work”? Is the stopwords corpus not found? If the setup doesn’t allow you to see the error message… you’ll need to figure out a way to see it anyway.

The PHP script is probably running as a different user, and failing to find nltk_data. The easiest solution might be to run `nltk.download(“stopwords”)` from within the PHP script, so as to download a copy into a location compatible with this set-up.

Alexis


--
You received this message because you are subscribed to the Google Groups "nltk-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nltk-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thien Vu Trong

unread,
Oct 17, 2017, 6:16:41 AM10/17/17
to nltk-users
Thanks, "does not work" mean that do nothing, and return "".
"The PHP script is probably running as a different user, and failing to find nltk_data. The easiest solution might be to run `nltk.download(“stopwords”)` from within the PHP script, so as to download a copy into a location compatible with this set-up." 
I also think about that, when I check, it run with "nginx" user, I have try to edit visudo to make permission to "nginx" user. As you recommend, I will review more about location and permission to get data from "stopwords".

Thien Vu Trong

unread,
Oct 17, 2017, 6:16:42 AM10/17/17
to nltk-users
I have find out solution, that is call python script from php with root user by adding "$command = escapeshellcmd("sudo -u root -S /usr/bin/python ......"


On Tuesday, 17 October 2017 05:38:20 UTC+7, Alexis wrote:

Dimitriadis, A. (Alexis)

unread,
Oct 17, 2017, 7:51:05 AM10/17/17
to nltk-...@googlegroups.com
That’s good, but it’s a Really Bad Idea to take commands from a webserver and pass them to a process running as root. You should figure out how to see the error messages that Python generates (it doesn’t just return “” without errors as well), and fix the problem properly.

Alexis

Dr. Alexis Dimitriadis | Assistant Professor and Senior Research Fellow | Utrecht Institute of Linguistics OTS | Utrecht University | Trans 10, 3512 JK Utrecht, room 2.33 | +31 30 253 65 68 | a.dimi...@uu.nl | www.hum.uu.nl/medewerkers/a.dimitriadis
Reply all
Reply to author
Forward
0 new messages