我的虚拟环境(python)是否导致我的 PYTHONPATH 损坏?

发布于 2024-10-11 15:02:44 字数 225 浏览 6 评论 0原文

在我的 /etc/profile 中,我将 PYTHONPATH 设置为某些内容。

但是当我 source myvirtual-env

然后在 python 中执行此操作时:

>>> import sys
>>> print sys.path

我在任何地方都看不到我的路径。

In my /etc/profile, I set PYTHONPATH as something.

But when I source myvirtual-env

And then do this in python:

>>> import sys
>>> print sys.path

I don't see my paths anywhere.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦过后 2024-10-18 15:02:44

这就是 virtualenv 的意义所在。它不会继承您的其他设置。如果您想要 PYTHONPATH,则需要显式设置一个。

这篇 djangousers 帖子可能会有所帮助,您想要使用 virtualenvwrapper 来解决这个问题。

更多信息请参阅这篇关于类似的帖子问题

That's the point of the virtualenv. It doesn't inherit from the rest of your setup. If you want a PYTHONPATH, you need to explicitly set one.

This djangousers post is probably helpful, you want to use virtualenvwrapper to solve this problem.

More info in this other SO post on a similar problem.

情话已封尘 2024-10-18 15:02:44

我没有在 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:为什么可以我仍然在 clean/new virtualenv 中导入旧模块似乎确认PYTHONPATH正在使用来构造sys.path当虚拟环境被激活时

I don't observe the problem with Python 2.7, virtualenv 1.7.1.2 on Windows XP and I suspect Paul McMillan's answer is wrong.

# 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'

Also python virtualenv: why can I still import old modules in clean/new virtualenv seems to confirm PYTHONPATH is being used to construct sys.path also when virtual environment is activated.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文