我试图使用带有uwsgi和主管的conda env运行Flask应用程序。
我设法解决了关于wsgi脚本路径的first issue,但我找不到如何设置conda env。
我的uwsgi配置文件/home/me/Development/flask/myflaskapp/myflaskapp.ini
是
[uwsgi]
module = wsgi
master = true
process = 2
chmod-socket = 666
chdir = /home/me/Development/flask/myflaskapp
socket = /home/me/Development/flask/myflaskapp/run/myflaskapp.sock
callable = app
vacuum = true
我的主管配置
[program:uwsgi-myflaskapp]
command=/home/me/Development/miniconda/envs/myflaskapp/bin/uwsgi /home/me/Development/flask/myflaskapp/myflaskapp.ini
autostart=true
autorestart=true
stdout_logfile=/home/me/Development/flask/myflaskapp/log/uwsgi-myflaskapp.log
redirect_stderr=true
exitcodes=0
当我通过主管开始uwsgi时,我得到了
*** Operational MODE: single process ***
Traceback (most recent call last):
File "./wsgi.py", line 1, in <module>
from myflaskapp import app
File "./myflaskapp/__init__.py", line 1, in <module>
from flask import Flask
ImportError: No module named flask
所以我猜我没有设置conda env。我该怎么设置它?
答案 0 :(得分:2)
我必须在我的超级用户配置文件中设置PATH
environment=PATH=/home/me/Development/miniconda/envs/myflaskapp/bin
答案 1 :(得分:2)
我知道它已经晚了但是这也应该有用
command=bash -c "source /path_to_conda/bin/activate && source activate env_name && program_to_run --config=config_path command"
答案 2 :(得分:0)
从命令行启动uwsgi以设置Python路径时使用-H标记
http://uwsgi-docs.readthedocs.org/en/latest/Options.html#virtualenv
因此,在您的情况下,在supervisor配置中,将命令更改为:
command=/home/me/Development/miniconda/envs/myflaskapp/bin/uwsgi -H /path/to/your/virtualenv /home/me/Development/flask/myflaskapp/myflaskapp.ini
您可以使用
找到您的virtualenv路径which python
在您的virtualenv激活的命令行上。