从脚本获取virtualenv的bin文件夹路径

问题描述:

我正在使用具有django项目的virtualenvwrapper,该项目具有自动写入一些配置文件的管理任务,因此用户只需要

I'm using virtualenvwrapper with a django project that has a management task that automatically writes some config files, so the user just has to

./manage.py generate_configuration > much_nice.conf

然后将文件移动到其他位置。生成的配置文件之一是启动芹菜工作者的超级用户任务。我得到的问题是,我不知道如何在virtualenv的bin文件夹中输出芹菜可执行文件的路径。本质上,我想输出命令

And then move the file elsewhere. One of the generated config files is a task for supervisord that launches a celery worker. The problem I'm getting is that I don't know how to output the path of the celery executable that is within the bin folder of the virtualenv. Essentially, I'd like to have the output of the command

which celery

一个选项是使用 sys.executable ,获取文件夹(这似乎是 bin 文件夹中的virtualenv),但是它是...但我不确定。

One option is using sys.executable, get the folder (which seems to be the bin folder of the virtualenv) and that's it... but I'm not sure.

不是virtualenv有获取路径本身的任何种类的方法?

Doesn't virtualenv have any kind of method to get the path itself?

虚拟环境变量的路径在环境变量VIRTUAL_ENV

The path to the virtual env is in the environment variable VIRTUAL_ENV

echo $VIRTUAL_ENV