在我的/ etc / profile中,我将PYTHONPATH设置为某种东西。
但是当我source myvirtual-env
然后在python中执行此操作:
>>> import sys
>>> print sys.path
我在任何地方都看不到我的路径。
答案 0 :(得分:5)
这就是virtualenv的重点。它不会从您的其他设置继承。如果你想要PYTHONPATH,你需要明确设置一个。
此djangousers post可能有用,您希望使用virtualenvwrapper来解决此问题。
答案 1 :(得分:0)
我没有在Windows XP上观察到Python 2.7,virtualenv 1.7.1.2的问题,我怀疑Paul McMillan的答案是错误的。
# PYTHONPATH not set
# output from python -c "import sys; print sys.path" (edited for clarity)
'',
'C:\\Program Files\\python\\2.7\\lib\\site-packages\\pip-1.1-py2.7.egg',
'C:\\WINDOWS\\system32\\python27.zip',
'C:\\Program Files\\python\\2.7\\DLLs',
'C:\\Program Files\\python\\2.7\\lib',
'C:\\Program Files\\python\\2.7\\lib\\plat-win',
'C:\\Program Files\\python\\2.7\\lib\\lib-tk',
'C:\\Program Files\\python\\2.7',
'C:\\Program Files\\python\\2.7\\lib\\site-packages',
'C:\\Program Files\\python\\2.7\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg-info'
# PYTHONPATH not set, virtualenv activated
# output from python -c "import sys; print sys.path" (edited for clarity)
'',
'c:\\python\\virtualenv\\2.7\\lib\\site-packages\\distribute-0.6.24-py2.7.egg',
'c:\\python\\virtualenv\\2.7\\lib\\site-packages\\pip-1.1-py2.7.egg',
'C:\\WINDOWS\\system32\\python27.zip',
'c:\\python\\virtualenv\\2.7\\DLLs',
'c:\\python\\virtualenv\\2.7\\lib',
'c:\\python\\virtualenv\\2.7\\lib\\plat-win',
'c:\\python\\virtualenv\\2.7\\lib\\lib-tk',
'c:\\python\\virtualenv\\2.7\\Scripts',
'C:\\Program Files\\python\\2.7\\Lib',
'C:\\Program Files\\python\\2.7\\DLLs',
'C:\\Program Files\\python\\2.7\\Lib\\lib-tk',
'c:\\python\\virtualenv\\2.7',
'c:\\python\\virtualenv\\2.7\\lib\\site-packages'
# PYTHONPATH set to c:\pythonpath_sample_dir
# output from python -c "import sys; print sys.path" (edited for clarity)
''
'C:\\Program Files\\python\\2.7\\lib\\site-packages\\pip-1.1-py2.7.egg'
'c:\\pythonpath_sample_dir' <--- value from PYTHONPATH
'C:\\WINDOWS\\system32\\python27.zip'
'C:\\Program Files\\python\\2.7\\DLLs'
'C:\\Program Files\\python\\2.7\\lib'
'C:\\Program Files\\python\\2.7\\lib\\plat-win'
'C:\\Program Files\\python\\2.7\\lib\\lib-tk'
'C:\\Program Files\\python\\2.7'
'C:\\Program Files\\python\\2.7\\lib\\site-packages'
'C:\\Program Files\\python\\2.7\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg-info'
# PYTHONPATH set to c:\pythonpath_sample_dir, virtualenv activated
# output from python -c "import sys; print sys.path" (edited for clarity)
''
'c:\\python\\virtualenv\\2.7\\lib\\site-packages\\distribute-0.6.24-py2.7.egg'
'c:\\python\\virtualenv\\2.7\\lib\\site-packages\\pip-1.1-py2.7.egg'
'c:\\pythonpath_sample_dir' <--- value from PYTHONPATH
'C:\\WINDOWS\\system32\\python27.zip'
'c:\\python\\virtualenv\\2.7\\DLLs'
'c:\\python\\virtualenv\\2.7\\lib'
'c:\\python\\virtualenv\\2.7\\lib\\plat-win'
'c:\\python\\virtualenv\\2.7\\lib\\lib-tk'
'c:\\python\\virtualenv\\2.7\\Scripts'
'C:\\Program Files\\python\\2.7\\Lib'
'C:\\Program Files\\python\\2.7\\DLLs'
'C:\\Program Files\\python\\2.7\\Lib\\lib-tk'
'c:\\python\\virtualenv\\2.7'
'c:\\python\\virtualenv\\2.7\\lib\\site-packages'
同样python virtualenv: why can I still import old modules in clean/new virtualenv似乎确认PYTHONPATH
正在使用来构建sys.path
,并在虚拟环境激活时 。