我创造了几个月的virtualenv。我遇到了一个问题。
当我激活虚拟环境时,我可以像django一样访问lib:
source virtualenv/jsms/bin/activate
(jsms)local% python
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> exit()
(jsms)local% deactivate
但是当我使用 bin 文件夹中的python时,我无法访问django:
local% virtualenv/jsms/bin/python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named django
更奇怪的是,当我从 bin 文件夹中使用 python3.4 时,我正在使用 python 2.7 :
local% virtualenv/jsms/bin/python3.4
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
您是否知道在 bin 文件夹中直接从python访问lib的方法?
答案 0 :(得分:2)
activate只是一个bash脚本,因此您可以随时查看激活文件并查看它在做什么,但我认为您正在寻找的是env变量PYTHONHOME
。我会尝试:
export OLD_PYTHON_HOME="$PYTHONHOME"
unset PYTHONHOME
virtualenv/jsms/bin/python3.4 --version
对于Windows,您将使用activate.bat模板中的以下代码:
if defined PYTHONHOME (
set _OLD_VIRTUAL_PYTHONHOME=%PYTHONHOME%
set PYTHONHOME=
)