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
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
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.
Doesn't virtualenv have any kind of method to get the path itself?
The path to the virtual env is in the environment variable VIRTUAL_ENV
You can use fabric to do such things from python
The
VIRTUAL_ENV
environment variable is only available if the virtual environment is activated.For instance:
If not activated, you have an exception:
IMO, you should use
sys.executable
to get the path of your Python executable, and then build the path to celery: