主管 - 运行 python 脚本 PYTHONPATH 问题
我正在使用主管运行 python 脚本:
[program:twitter_track]
autorestart = true
numprocs = 1
autostart = false
redirect_stderr = True
stopwaitsecs = 1
startsecs = 1
priority = 99
command = python /home/ubuntu/services/twitter.py track
startretries = 3
stdout_logfile = /home/ubuntu/logs/twitter_track.log
但进程无法启动。以下是错误日志的内容:
Traceback (most recent call last):
File "/home/ubuntu/services/twitter.py", line 6, in <module>
from mymodule.twitter.stream import TwitterStream
ImportError: No module named mymodule.twitter.stream
Traceback (most recent call last):
File "/home/ubuntu/services/twitter.py", line 6, in <module>
似乎获取了 mymodule,但是如果我自己运行 twitter.py,一切正常,只有当我通过主管运行它时才会抛出此错误。
我将 mymodule 添加到我的 ~/.profile 文件中的 PYTHONPATH 中,如下所示:
export PYTHONPATH=$PYTHONPATH:/home/ubuntu/lib
是否有任何原因导致脚本在通过终端运行时有效,但在通过主管运行时无效?任何帮助将不胜感激。
I am using supervisor to run a python script:
[program:twitter_track]
autorestart = true
numprocs = 1
autostart = false
redirect_stderr = True
stopwaitsecs = 1
startsecs = 1
priority = 99
command = python /home/ubuntu/services/twitter.py track
startretries = 3
stdout_logfile = /home/ubuntu/logs/twitter_track.log
But the process fails to start. Here is what the error log says:
Traceback (most recent call last):
File "/home/ubuntu/services/twitter.py", line 6, in <module>
from mymodule.twitter.stream import TwitterStream
ImportError: No module named mymodule.twitter.stream
Traceback (most recent call last):
File "/home/ubuntu/services/twitter.py", line 6, in <module>
It seems that obtain mymodule, but if I run twitter.py on it's own, everything works fine, it only throws this error when I run it through supervisor.
I added mymodule to the PYTHONPATH in my ~/.profile file like so:
export PYTHONPATH=$PYTHONPATH:/home/ubuntu/lib
Is there any reason why the script would work when run through terminal but not when run through supervisor? Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将
PYTHONPATH
定义添加到supervisord 配置文件中的environment
指令中。它应该位于您的[program:twitter_track]
部分下,如下所示:这将确保您的 python 进程在supervisord 启动时看到正确的
PYTHONPATH
。Add the
PYTHONPATH
definition to theenvironment
directive in the supervisord configuration file. It should go under your[program:twitter_track]
section, like so:This will ensure that that your python process sees the proper
PYTHONPATH
when supervisord starts it.将 PYTHONPATH 定义添加到环境中:
Add the PYTHONPATH definition to the environment:
@Darren Griffith 给出正确的解决方案。但如果我们送走文档
http://supervisord.org/configuration.html#program-x-section-设置 ->环境
我们哭了,它说
因此您需要使用引号 ""
@Darren Griffith give right solution. But if we see off docs
http://supervisord.org/configuration.html#program-x-section-settings -> environment
We wee, that it says
So you need use a quotes ""