PHP exec python无法正常工作 [英] PHP exec python not working

查看:113
本文介绍了PHP exec python无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,你们.我在Dreamhost的网络服务器上运行python.我正在使用他们的python安装程序,并且正在使用一个lastfm模块,该模块可以在这里找到: http://code.google.com/p/python-lastfm/

hey yall. Im running python on a webserver from dreamhost. I am using their install of python and am using a lastfm module that can be found here: http://code.google.com/p/python-lastfm/

要使其正确导入,我会这样做

to get it to import properly i do this

import sys
sys.path.append("/home/myusername/build/Python-2.5/Lib/site-packages/")
import lastfm

因为在那里安装了lastfm模块.

since the lastfm module is installed there.

当我使用腻子ssh进入服务器时,我可以简单地运行python test.py,它可以完美运行.但是当我使用

When I use putty to ssh into my server, i can simply run python test.py and it works perfectly. But when i run it from a php script with

exec("python test.py");

它可能无法正常运行,并且脚本无法运行.

it suppossedly does not work and the script doesnt run. it runs perfectly fine when i do

import lastfm

然后有其他事情, 但是当我实际上尝试使用以下模块进行操作时:

and then have other things after, but when i actually try to do something with the module like:

import lastfm
api=lastfm.Api(api_key)

它不运行.我再次可以在外壳中使用相同的python安装来运行脚本,并且执行得很好.因此,当我从php脚本运行它时,一定会发生某些错误.我认为它将运行完全相同的python和所有内容.我检查了其他帖子,他们说这可能是具有文件许可权的内容,但是我将每个文件都设为777,但仍然无法正常工作. idk可能是什么问题.预先感谢大家.

it does not run. once again i can run the script using the same python install in a shell and it executes fine. So something must be happening that goes wrong when i run it from the php script. I figured it would be running the exact same python and everything. I checked other posts and they say it may be something with file permissions, but ive put every file to 777 and it still doesnt work. idk what the problem could be. thanks in advance everyone.

推荐答案

python引发的任何错误都将传递给孩子的stderr.尝试告诉php从stderr读取,或者(在python中)执行以下操作:

Whatever error python is raising would be going to the child's stderr. Try either telling php to read from stderr, or (in python) do this:

import sys
sys.stderr = sys.stdout

这篇关于PHP exec python无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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