Python 如何在主管中使用 virtualenvwrapper?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15202760/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use virtualenvwrapper in Supervisor?
提问by MLister
When I was developing and testing my project, I used to use virtualenvwrapper to manage the environment and run it:
在我开发和测试我的项目时,我曾经使用 virtualenvwrapper 来管理环境并运行它:
workon myproject
python myproject.py
Of course, once I was in the right virtualenv, I was using the right version of Python, and other corresponding libraries for running my project.
当然,一旦我在正确的 virtualenv 中,我就会使用正确版本的 Python 和其他相应的库来运行我的项目。
Now, I want to use Supervisord to manage the same project as it is ready for deployment. The question is what is the proper way to tell Supervisord to activate the right virtualenv before executing the script? Do I need to write a separate bash script that does this, and call that script in the command field of Supervisord config file?
现在,我想使用 Supervisord 来管理相同的项目,因为它已准备好进行部署。问题是在执行脚本之前告诉 Supervisord 激活正确的 virtualenv 的正确方法是什么?我是否需要编写一个单独的 bash 脚本来执行此操作,并在 Supervisord 配置文件的命令字段中调用该脚本?
采纳答案by dm03514
One way to use your virtualenv from the command line is to use the python executable located inside of your virtualenv.
从命令行使用 virtualenv 的一种方法是使用位于 virtualenv 中的 python 可执行文件。
for me i have my virtual envs in .virtualenvsdirectory. For example
对我来说,我在.virtualenvs目录中有我的虚拟环境。例如
/home/ubuntu/.virtualenvs/yourenv/bin/python
/home/ubuntu/.virtualenvs/yourenv/bin/python
no need to workon
没有必要 workon
for a supervisor.confmanaging a tornado app i do:
对于supervisor.conf管理龙卷风应用程序,我这样做:
command=/home/ubuntu/.virtualenvs/myapp/bin/python /usr/share/nginx/www/myapp/application.py --port=%(process_num)s
回答by onur güng?r
First, run
第一次运行
$ workon myproject
$ dirname `which python`
/home/username/.virtualenvs/myproject/bin
Add the following
添加以下内容
environment=PATH="/home/username/.virtualenvs/myproject/bin"
to the related supervisord.conf under [program:blabla] section.
到 [program:blabla] 部分下的相关 supervisord.conf。
回答by Stephen Fuhry
Add your virtualenv/bin path to your supervisord.conf's environment:
将您的 virtualenv/bin 路径添加到您的supervisord.conf's environment:
[program:myproj-uwsgi]
process_name=myproj-uwsgi
command=/home/myuser/.virtualenvs/myproj/bin/uwsgi
--chdir /home/myuser/projects/myproj
-w myproj:app
environment=PATH="/home/myuser/.virtualenvs/myproj/bin:%(ENV_PATH)s"
user=myuser
group=myuser
killasgroup=true
startsecs=5
stopwaitsecs=10

