Macports 和 virtualenv 站点包 后备

发布于 2024-10-11 13:27:20 字数 2233 浏览 3 评论 0原文

我已经安装了 django 和 python 此链接 建议使用 macports。但是,我想使用 virtualenv 来安装更多软件包。我的理解是,如果我--no-site-packages传递给virtualenv,我应该获取当前安装的软件包除了我安装到虚拟环境中的任何软件包之外。这是正确的吗?

举个例子,我通过 macports 安装了 django,然后创建了一个虚拟环境,但我无法从该虚拟环境中导入 django:

[streeter@mordecai]:~$ mkvirtualenv django-test
New python executable in django-test/bin/python
Installing setuptools............done.
...
(django-test)[streeter@mordecai]:~$ pip install django-debug-toolbar
Downloading/unpacking django-debug-toolbar
  Downloading django-debug-toolbar-0.8.4.tar.gz (80Kb): 80Kb downloaded
  Running setup.py egg_info for package django-debug-toolbar
Installing collected packages: django-debug-toolbar
  Running setup.py install for django-debug-toolbar
Successfully installed django-debug-toolbar
Cleaning up...
(django-test)[streeter@mordecai]:~$ python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
[GCC 4.2.1 (Apple Inc. build 5646)] 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
>>>

所以我可以将包安装到虚拟环境中,但它没有获取全局站点 -包。或者我没有正确执行某些操作/遗漏某些内容/误解 virtualenv 的工作原理?

我已经安装了 Mac OS 10.6 (Snow Leopard),更新了我的 macports 软件包,并且正在使用 macports 的 python26(通过 python_select python26)。

编辑:

我还检查了我的 macports PATH 设置是否正确。以下是一些输出:

[streeter@mordecai]:~$ python --version
Python 2.6.6
[streeter@mordecai]:~$ echo $PATH
/opt/local/bin:/opt/local/sbin:/Users/streeter/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/streeter/.ec2/bin
[streeter@mordecai]:~$ source dev/python-environments/test/bin/activate
(test)[streeter@mordecai]:~$ python --version
Python 2.6.1
(test)[streeter@mordecai]:~$ 

virtualenvvirtualenvwrapper 均使用 pip 安装,而不是使用 macports,因为这似乎没有创建源文件/usr/local/bin/virtualenvwrapper.sh,所以我不确定如何获取 virtualenvwrapper 的别名。

I've installed django and python as this link suggested with macports. However, I'd like to use virtualenv to install more packages. My understanding is that if I do not pass in the --no-site-packages to virtualenv, I should get the currently installed packages in addition to whatever packages I install into the virtual environment. Is this correct?

As an example, I've installed django through macports and then create a virtual environment, but I cannot import django from within that virtual environment:

[streeter@mordecai]:~$ mkvirtualenv django-test
New python executable in django-test/bin/python
Installing setuptools............done.
...
(django-test)[streeter@mordecai]:~$ pip install django-debug-toolbar
Downloading/unpacking django-debug-toolbar
  Downloading django-debug-toolbar-0.8.4.tar.gz (80Kb): 80Kb downloaded
  Running setup.py egg_info for package django-debug-toolbar
Installing collected packages: django-debug-toolbar
  Running setup.py install for django-debug-toolbar
Successfully installed django-debug-toolbar
Cleaning up...
(django-test)[streeter@mordecai]:~$ python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
[GCC 4.2.1 (Apple Inc. build 5646)] 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
>>>

So I can install packages into the virtual environment, but it isn't picking up the global site-packages. Or am I not doing something correctly / missing something / misunderstanding how virtualenv works?

I've got Mac OS 10.6 (Snow Leopard), have updated my macports packages and am using macports' python26 (via python_select python26).

Edit:

Also I've checked that my macports PATH is setup correctly. Here's some output:

[streeter@mordecai]:~$ python --version
Python 2.6.6
[streeter@mordecai]:~$ echo $PATH
/opt/local/bin:/opt/local/sbin:/Users/streeter/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/streeter/.ec2/bin
[streeter@mordecai]:~$ source dev/python-environments/test/bin/activate
(test)[streeter@mordecai]:~$ python --version
Python 2.6.1
(test)[streeter@mordecai]:~$ 

virtualenv and virtualenvwrapper were both installed using pip, not using macports as that didn't seem to create a file to source at /usr/local/bin/virtualenvwrapper.sh, so I'm not sure how to get the aliases for virtualenvwrapper.

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

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

发布评论

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

评论(1

罗罗贝儿 2024-10-18 13:27:20

从显示的版本和日期可以看出,您没有使用 MacPorts Python。 (尝试输入 /usr/bin/python2.6,然后输入 /opt/local/bin/python2.6。)只需设置 MacPorts python_select如果您不将 MacPorts bin 目录放在 shell 执行 PATH 的首位,则没有任何好处:

$ export PATH=/opt/local/bin:$PATH

您可能需要重新创建 virtualenv 以确保使用 MacPorts Python 而不是 Apple 提供的 Python。

编辑:有了附加信息,我猜想您的 $PATH 在最初采购virtualwrapper.sh之前没有正确设置,如此处。我建议您返回并按照那里的说明进行操作,确保您确实已将 virtualenvvirtualenvwrapper 安装到 MacPorts site-packages 目录,而不是系统 Python 目录。请注意,当前通过 MacPorts for Python 2.6 提供的 virtualenvwrapper 版本是较旧的版本 1.20;它的 shell 脚本有不同的名称

You are not using the MacPorts Python as evidenced by the version and date displayed. (Try typing /usr/bin/python2.6 and then /opt/local/bin/python2.6.) Just setting MacPorts python_select does no good if you do not put the MacPorts bin directory first on your shell execution PATH:

$ export PATH=/opt/local/bin:$PATH

You may need to recreate the virtualenv making sure you are using the MacPorts Python instead of the Apple-supplied Python.

EDIT: With the additional information, I would guess that your $PATH was not set properly prior to initially sourcing virtualwrapper.sh as described here. I suggest you go back and follow the instructions there, making sure you have really installed virtualenv and virtualenvwrapper to the MacPorts site-packages directory, and not the system Python's. Note, the version of virtualenvwrapper currently available through MacPorts for Python 2.6 is an older one, 1.20; the shell script for it has a different name.

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