如果你想运行的virtualenv下一个Python子,你可以做,通过使用Python解释器的virtualenv的/ bin /目录生活运行脚本:如果你想激活
# path to a python interpreter that runs any python script
# under the virtualenv /path/to/virtualenv/
python_bin = "/path/to/virtualenv/bin/python"
# path to the script that must run under the virtualenv
script_file = "must/run/under/virtualenv/script.py"
subprocess.Popen([python_bin, script_file])
然而当前Python解释器,而不是一个子进程下的virtualenv,您可以使用脚本activate_this.py
:
# doing execfile() on this file will alter the current interpreter's
# environment so you can import libraries in the virtualenv
activate_this_file = "/path/to/virtualenv/bin/activate_this.py"
execfile(activate_this_file, dict(__file__=activate_this_file))
你的意思是这样的吗? https://bitbucket.org/ianb/virtualenv/src/1f9dfb2437f1/virtualenv_support/activate_this.py –