What Is The Difference Between Running A Script From The Command Line And From Exec() With Php?
I'm trying to run a Python script using exec() from within PHP. My command works fine when I run it directly using a cmd window, but it produces an error when I run it from exec()
Solution 1:
You have to run nltk.download()
and choose 'maxent_treebank_pos_tagger'. You must make a python script and in it put:
#!/usr/bin/pythonimport nltk
nltk.download('maxent_treebank_pos_tagger');
then run it from command line. It will install the data files for the POS tagges, which you don't have installed yet.
After you do this it should work.
Solution 2:
Your web server likely runs with other privileges than yourself. Possible problems include:
- Path/file permission: can the web server user access the files it needs?
- Different environment: are all necessary environment variables (PATH, Python-specific stuff, …) set?
- Configuration: are there per-user configurations for Python or the module?
Tip: execute set in both the command prompt and from the PHP process and check the differences.
Solution 3:
From the shell/terminal, you can use:
sudo python -m nltk.downloader maxent_treebank_pos_tagger
It will install maxent_treebank_pos_tagger
(i.e. the standard treebank POS tagger in NLTK).
Post a Comment for "What Is The Difference Between Running A Script From The Command Line And From Exec() With Php?"