pythonvirtualenvpythonbrew

How can I run a python script using pythonbrew venv from the command line?


I recently came across this in a cron script at my place of work:

/bin/bash -c "[[ -s $HOME/.pythonbrew/etc/bashrc ]] && source $HOME/.pythonbrew/etc/bashrc && pythonbrew use 2.6.7 && pythonbrew venv use someapp && python /opt/someapp/bin/someapp.py"

This is for a system-wide (multi-user) installation of Pythonbrew.

It works. But please tell me there's a better way.

Addendum

To clarify what I'm looking for: I'd like a one-line command to run my script though a virtualenv tied to pythonbrew. With virtualenv alone, I could do something like this:

/opt/someapp/venv/bin/python /opt/someapp/bin/someapp.py

What I don't want is another script to run my script (like that cron command above).


Solution

  • I believe it can be done by using the python binary directly from you pythonbrew virtual environment. By default its in ~/.pythonbrew/venvs/Python-<version>/<name of venv>/bin/python But I think you can change the path with an environmental variable.

    So just change the first half of the line you added to reference the pythonbrew virtual environment python binary and it should work.