Can't import NLTK from within phps shell_exec

◇◆丶佛笑我妖孽 提交于 2019-12-10 11:24:46

问题


I have a python script being called form php's shell_exec command. All works well, except that it cannot import the NLTK corpora when called through shell_exec. The very same command is executed without problems however, whenever I call it directly from shell. I am using Debian 8.

This is my php-Code:

$cmd = "/usr/bin/python /var/www/include/sCrape.py -u '$my_url' ";
$response = shell_exec($cmd);
$response = json_decode($response, true);

This command works well when called directly (without sudo) from the root:

/usr/bin/python /var/www/include/sCrape.py -u '$my_url' 

The error message from the python script I get (only when I call from PHP's shell_exec) is:

Traceback (most recent call last): 
File "/var/www/include/sCrape.py",
    line 221, in main() File "/var/www/include/sCrape.py", 
    line 211, in main sc = sCrapeClass() 
File "/var/www/include/sCrape.py", 
    line 61, in __init__ self._stopwords = set(stopwords.words('english') + list(punctuation)) 
File "/usr/local/lib/python2.7/dist-packages/nltk/corpus/util.py", 
    line 99, in __getattr__ self.__load() 
File "/usr/local/lib/python2.7/dist-packages/nltk/corpus/util.py", 
    line 64, in __load except LookupError: 
raise e LookupError:    **********************************************************************     Resource u'corpora/stopwords' not found. 
Please use the NLTK Downloader to obtain the resource: 
>>> nltk.download() Searched in: - '/var/www/nltk_data' -
'usr/share/nltk_data' - '/usr/local/share/nltk_data' -
'/usr/lib/nltk_data' - '/usr/local/lib/nltk_data' **********************************************************************

来源:https://stackoverflow.com/questions/35830893/cant-import-nltk-from-within-phps-shell-exec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!