我正在与virtualenv一起在生产服务器上部署Django,并且无法在服务器上激活virtualenv
source .../bin/activate
我做了一些研究,发现python路径会根据我们是否属于virtualenv而改变。
sys.path(激活virtualenv)
['',
'/.../virtualenv/test_path/bin',
'/.../virtualenv/test_path/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
'/.../virtualenv/test_path/local/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg',
'/.../virtualenv/test_path/lib/python2.7',
'/.../virtualenv/test_path/lib/python2.7/plat-linux2',
'/.../virtualenv/test_path/lib/python2.7/lib-tk',
'/.../virtualenv/test_path/lib/python2.7/lib-old',
'/.../virtualenv/test_path/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/.../virtualenv/test_path/local/lib/python2.7/site-packages',
'/.../virtualenv/test_path/local/lib/python2.7/site-packages/IPython/extensions']
sys.path(不激活virtualenv):
['',
'/usr/local/bin',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PIL',
'/usr/lib/python2.7/dist-packages/gst-0.10',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.7',
'/usr/local/lib/python2.7/dist-packages/IPython/extensions']
只需将pythonpath更改为指向virtualenv
就足够了.../python2.7/site-packages
文件夹以获得与运行
相同的结果source .../bin/activate
?
答案 0 :(得分:2)
不,不是。 virtualenv不仅仅是关于site-packages
,而是关于整个孤立的python环境。
执行source /path/to/venv/bin/activate
只需更改您的$PATH
环境变量,即可将您的virtualenv bin
目录包含在首次查找中。
如果直接致电python
,它只是一个快捷方式:
$ /path/to/venv/bin/python myscript.py
如果您在激活的virtualenv中调用pip
,则它与以下内容相同:
$ /path/to/venv/bin/pip install XYZ