什么是命令行和EXEC()与PHP运行脚本之间的区别? [英] What is the difference between running a script from the command line and from exec() with PHP?

查看:259
本文介绍了什么是命令行和EXEC()与PHP运行脚本之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行一个Python脚本执行exec()在PHP。我的命令工作正常,当我运行它,直接使用 CMD 窗口,但它产生的时候,我从运行EXEC()的错误在PHP。

我的Python脚本使用 NTLK 找到专有名词。示例命令:

 C:\\ Python25 \\ python.exeC:\\ WAMP \\项目\\ python的\\干线\\试验\\ find_proper_nouns.py我今天早上去了伦敦

收益 [伦敦] 当我从 CMD 运行,但投在Apache的错误日志,当我请从相同的命令执行exec() .The脚本defintely越来越运行正常 - 如果我改变了python脚本是打印的Hello World时返回正常。

我知道这是一个很大的要求,任何人知道如何解决这个NLTK错误,但是我真的可以做任何指针,为什么从 EXEC运行它是不同的到 CMD 。 (该命令是相同的)。

我在Windows 7上运行WAMP与Apache 2.2.11。

下面是在Apache日志中的错误:

 回溯(最后最近一次调用):
  文件C:\\ WAMP \\项目\\ python的\\干线\\试验\\ find_proper_nouns_command_line.py,6号线,上述<&模块GT;
    部分= nltk.pos_tag(文本)
  文件C:\\ Python25 \\ lib目录\\站点包\\ NLTK \\标签\\ __ init__.py62行,在pos_tag
    恶搞= nltk.data.load(_POS_TAGGER)
  文件C:\\ Python25 \\ lib目录\\站点包\\ NLTK \\ data.py,线路590,在负荷
    resource_val =和pickle.load(_open(resource_url))
  文件C:\\ Python25 \\ lib目录\\站点包\\ NLTK \\ data.py,669线,在_open
    返回查找(路径)。开()
  文件C:\\ Python25 \\ lib目录\\站点包\\ NLTK \\ data.py,451线,在发现
    提高LookupError(resource_not_found)
LookupError:
************************************************** ********************
  资源'标注器/ maxent_treebank_pos_tagger / english.pickle不
  找到。请使用NLTK下载器来获取资源:
  >>> nltk.download()。
  搜索在:
     - C:\\\\ nltk_data
     - D:\\\\ nltk_data
     - E:\\\\ nltk_data
     - C:\\\\ Python25 \\\\ nltk_data
     - C:\\\\ Python25 \\\\ lib目录\\\\ nltk_data
     - C:\\\\ \\\\的Windows \\\\ SYSTEM32 \\\\配置\\\\ systemprofile AppData的\\\\ \\\\漫游nltk_data
************************************************** ********************


解决方案

您的Web服务器有可能与其他特权比你运行。可能的问题包括:


  • 路径/文件权限:可以在Web服务器的用户访问它需要的文件

  • 不同的环境:是(PATH,Python特定的东西,...)设置所有必要的环境变量

  • 配置:是否有每个用户的配置使用Python或模块

提示:执行<大骨节病>同时在命令提示符下,并从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() in PHP.

My Python script uses NTLK to find 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] when I run it from cmd, but throws an error in the Apache log when I run the same command from exec().The script is defintely getting run OK - if I change the python script to be print "Hello World" that is returned fine.

I know it's a big ask for anyone to know how to fix this NLTK error, but I could really do with any pointers as to why running it from exec is different to cmd. (The command is identical).

I'm running WAMP on Windows 7 with Apache 2.2.11.

Here's the error in 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)
LookupError: 
**********************************************************************
  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'
**********************************************************************

解决方案

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.

这篇关于什么是命令行和EXEC()与PHP运行脚本之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆