在 Mac Snow Leopard 上处理系统 python 和 python 27 时出现问题

发布于 2024-12-21 15:10:34 字数 403 浏览 0 评论 0原文

我在 mac os x 雪豹上安装 geoDjango 时遇到了很多问题。

尘埃落定后,我意识到 python (2.6) 的系统安装位于 psycopg2 的接收端,

Python 2.7 位于系统路径上。当我在终端中调用 python 时,将启动 python 2.7。

但是,如果我对 psycopg2 进行 easy_install 或 mac 端口安装,它不会安装到 Libraries/framework.python/verisons/2.7/lib 或 bin (我在这里根据内存工作)。不过,我确实在 python 2.6 的系统安装中找到了安装的副本

如何获取 mac port 和 easy_install 等内容以定位 python 2.7 并忽略系统 python?

I had a lot of problems getting geoDjango installed on mac os x snow leopard.

After the dust settled, I realized that the system install of python (2.6) was on the recieivng end of psycopg2

Python 2.7 is on the system path. And when I invoke python in the terminal, python 2.7 is the one the is fired up.

But if I do an easy_install, or mac port install of psycopg2, it doesn't get installed to Libraries/framework.python/verisons/2.7/lib or bin (i am working from memory here). I do however find a copy installed in the system install of python 2.6

How do I get things like mac port and easy_install to target python 2.7 and ignore the system python?

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

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

发布评论

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

评论(2

江湖正好 2024-12-28 15:10:34

解决这个问题的最佳方法是使用 virtualenv。创建虚拟环境时,您可以选择 (-p) 来指定所需的 Python 可执行文件。一旦进入 virtualenv,您就完全不必担心它,所有常规命令(包括 pip)都将引用正确的 Python 可执行文件、站点包、库等 例如,

如果您想为 MacPort 的 Python 2.7 创建 virtualenv,您可以执行

以下操作: $ virtualenv -p /opt/local/bin/python2.7 myvirtualenv

The best way to solve this is to use virtualenv. When you create a virtual environment, you have the option (-p) of specifying which Python executable you want. Once you're in the virtualenv, you don't have to worry about it at all, and all your regular commands (including pip) will refer to the proper Python executable, site packages, libraries, etc.

E.g. if you want to create a virtualenv for MacPort's Python 2.7, you can do:

$ virtualenv -p /opt/local/bin/python2.7 myvirtualenv

只有影子陪我不离不弃 2024-12-28 15:10:34

如果您使用 macports 那么您应该在系统目录之前的路径上有 /opt/local/bin ,然后您可以使用 port select python python27 选择 macports pyton 2.7 。在这种情况下,port select 会更改 /opt/local/bin 中的符号链接以指向已安装的 macports 2.7,即使在这种情况下,您也需要调用 easy_install-2.7 而不仅仅是 easy_install。另外,我通常通过显式 python 版本安装您想要的 macports,例如 py27-psycopg2、py26-psycopg2.. 我认为 py-psycopg2 最近已更改,因此它会选择 portselect python 选择的 python。

问题是你在路径上找到的 easy_install 可能是 Apple 的,并且 easy_install 包含 python 解释器在其内部的位置。因此,您需要一个 easy_install 来匹配您拥有的每个解释器。

macports 不提供 eaxy_install,但每个版本只提供一个,因此您可以说 macports python2.7 和 3.2。

如果你有其他Python,例如来自python.org,然后安装setuptools或dustribute,你将获得该Python的easy_install,它将位于/usr/local/bin中。

If you are using macports then you shouldhave /opt/local/bin on your path before the systems directories and then you can use port select python python27 to choose the macports pyton 2.7 . port select in this case changes symbolic links in /opt/local/bin to point to the macports installed 2.7, even in this case you do need to call easy_install-2.7 not just easy_install. Also the macports you want I usually install via an explicit python version e.g. py27-psycopg2, py26-psycopg2.. I think py-psycopg2 has recently been changed so it picks up the python selected by portselect python.

What the issue is that the easy_install you find on the path is probably the Apple one and easy_install includes the location of the python interpreter inside itself. So you need an easy_install to match each interpreter you have.

macports does not provide a eaxy_install but only one for each version so you can have say a macports python2.7 and 3.2.

If you have other pythons e.g. from python.org and then install setuptools or dustribute you will get an easy_install for that python and that will be in /usr/local/bin.

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