为什么 virtualenv 不包含所有系统路径?

发布于 2024-09-30 20:59:40 字数 122 浏览 1 评论 0原文

我创建了一个 virtualenv,虽然它有很多系统路径,但没有其他路径。具体来说,似乎不包括 pyshared 和 dist-packages。因此,我的系统范围内的 MySQLdb 和 psycopg2 不可用。有什么想法吗?

I created a virtualenv, and while it has many system paths, it doesn't have others. Specifically, pyshared and dist-packages don't seem to be included. As a result, my system-wide MySQLdb and psycopg2 aren't available. Any ideas why?

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

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

发布评论

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

评论(2

痕至 2024-10-07 20:59:40

似乎与 Ubuntu 与 python 的混乱有关虚拟环境

甚是思念 2024-10-07 20:59:40

我知道的唯一可能的方法是,如果您使用参数 --no-site-packages:

from 这里

如果您使用 virtualenv 构建
--no-site-packages ENV 它不会继承任何包
/usr/lib/python2.5/site-packages (或
无论您的全球站点包在哪里
目录是)。如果您可以使用此功能
无法控制站点包
并且不想依赖
那里有包裹,或者你只是想要更多
与全球系统隔离。

所以这里有一个例子来了解更多:

首先我将正常创建一个 virtualenv (没有 --no-site-package ),你会看到
我总是可以访问安装在我的系统站点包(或 dist-packages)中的 django:

$ virtualenv A
New python executable in A/bin/python
Installing setuptools............done
$ source A/bin/activate
(A)$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django  
>>> django.__file__
'/usr/local/lib/python2.6/dist-packages/django/__init__.pyc'

但现在我将使用 --no-site-package 创建虚拟环境:

$ virtualenv B --no-site-package
New python executable in B/bin/python
Installing setuptools............done.
$ source B/bin/activate
(B)$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
[GCC 4.4.3] on linux2
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

现在您看到 virtaulenv能够从我的机器中的系统 dist-packages (ubuntu) 访问 django。

希望这会有所帮助:)

The only possible way that i'm aware of, is if you have created your virtualenv with the argument --no-site-packages:

from Here:

If you build with virtualenv
--no-site-packages ENV it will not inherit any packages from
/usr/lib/python2.5/site-packages (or
wherever your global site-packages
directory is). This can be used if you
don't have control over site-packages
and don't want to depend on the
packages there, or you just want more
isolation from the global system.

so Here is an example to understand more:

First i will create a virtualenv normally (without --no-site-package) and you will see that
i can always access django that is installed in my system site-packages (or dist-packages):

$ virtualenv A
New python executable in A/bin/python
Installing setuptools............done
$ source A/bin/activate
(A)$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django  
>>> django.__file__
'/usr/local/lib/python2.6/dist-packages/django/__init__.pyc'

But now i will create the virtual env using --no-site-package:

$ virtualenv B --no-site-package
New python executable in B/bin/python
Installing setuptools............done.
$ source B/bin/activate
(B)$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
[GCC 4.4.3] on linux2
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

now you see that virtaulenv was able to access django from system dist-packages (ubuntu) in my machine.

Hope this will help :)

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