I am attempting to operate a Python script using professional() from inside PHP. My command works fine after i run it directly utilizing a cmd window, however it produces a mistake after i run it from exec() in PHP.

My Python script uses NTLK to locate proper nouns. Example command:

"C:\Python25\python.exe" "C:\wamp\projects\python\trunk\tests\find_proper_nouns.py" "I went to London this morning" 

returns [London] after i run it from cmd, but throws a mistake within the Apache log after i run exactly the same command from exec().The script is defintely getting run OK - basically alter the python script to become print "Hello World" that's came back fine.

I understand it is a large request for anybody to understand how to fix this NLTK error, however i could do with any pointers why running it from exec differs to cmd. (The command is similar).

I am running WAMP on Home windows 7 with Apache 2.2.11.

Here's the mistake within the Apache log:

Traceback (most recent call last):
  File "C:\wamp\projects\python\trunk\tests\find_proper_nouns_command_line.py", line 6, in <module>
    parts = nltk.pos_tag(text)
  File "C:\Python25\lib\site-packages\nltk\tag\__init__.py", line 62, in pos_tag
    tagger = nltk.data.load(_POS_TAGGER)
  File "C:\Python25\lib\site-packages\nltk\data.py", line 590, in load
    resource_val = pickle.load(_open(resource_url))
  File "C:\Python25\lib\site-packages\nltk\data.py", line 669, in _open
    return find(path).open()
  File "C:\Python25\lib\site-packages\nltk\data.py", line 451, in find
    raise LookupError(resource_not_found)
  Resource 'taggers/maxent_treebank_pos_tagger/english.pickle' not
  found.  Please use the NLTK Downloader to obtain the resource:
  >>> nltk.download().
  Searched in:
    - 'C:\\nltk_data'
    - 'D:\\nltk_data'
    - 'E:\\nltk_data'
    - 'C:\\Python25\\nltk_data'
    - 'C:\\Python25\\lib\\nltk_data'
    - 'C:\\Windows\\system32\\config\\systemprofile\\AppData\\Roaming\\nltk_data'

You need to run nltk.download() and select 'maxent_treebank_pos_tagger'. You have to create a python script as well as in it put:

import nltk

then run it from command line. It'll install the information files for that POS tagges, which you do not have installed yet.

Once you do that it will work.

Your internet server likely runs along with other rights than yourself. Potential problems include:

  • Path/file permission: can the net server user access the files it requires?
  • Different atmosphere: are necessary atmosphere variables (PATH, Python-specific stuff, …) set?
  • Configuration: exist per-user designs for Python or even the module?

Tip: execute set both in the command prompt and in the PHP process and appearance the variations.