macos OS X Leopard 上的多个 Python 版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1218891/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Multiple versions of Python on OS X Leopard
提问by tomvon
I currently have multiple versions of Python installed on my Mac, the one that came with it, a version I downloaded recently from python.org, an older version used to run Zope locally and another version that Appengine is using. It's kind of a mess. Any recommendations of using one version of python to rule them all? How would I go about deleted older versions and linking all of my apps to a single install. Any Mac specific gotchas I should know about? Is this a dumb idea?
我目前在我的 Mac 上安装了多个版本的 Python,一个是它附带的版本,一个是我最近从 python.org 下载的版本,一个是用于在本地运行 Zope 的旧版本,另一个是 Appengine 正在使用的版本。有点乱。使用一个版本的 python 来统治它们的任何建议?我将如何删除旧版本并将我的所有应用程序链接到单个安装。我应该知道的任何 Mac 特定问题?这是一个愚蠢的想法吗?
采纳答案by Ned Deily
There's nothing inherently wrong with having multiple versions of Python around. Sometimes it's a necessity when using applications with version dependencies. Probably the biggest issue is dealing with site-package dependencies which may vary from app to app. Tools like virtualenv
can help there. One thing you should notdo is attempt to remove the Apple-supplied Python in /System/Library/Frameworks and linked to from /usr/bin/python. (Note the recent discussion of multiple versions here.)
拥有多个版本的 Python 并没有本质上的错误。有时在使用具有版本依赖关系的应用程序时这是必要的。可能最大的问题是处理可能因应用程序而异的站点包依赖项。像这样的工具virtualenv
可以提供帮助。你应该有一两件事不能做的是试图删除Apple提供的Python在/系统/图书馆/框架和链接到从/ usr / bin中/ Python的。(请注意近期多个版本的讨论在这里。)
回答by ken
Ian Bicking's virtualenvallows me to have isolated Pythons for each application I build, and lets me decide whether or not to include the global site-packages in the isolated Python environment.
Ian Bicking 的virtualenv允许我为我构建的每个应用程序使用隔离的 Python,并让我决定是否在隔离的 Python 环境中包含全局站点包。
I haven't tried it with Zope, but I'm guessing that the following should work nicely:
我还没有在 Zope 上试过,但我猜以下应该可以很好地工作:
- Using your Zope's Python, make a new virtualenv, either with or without --no-site-packages
- Drop your Zope into the virtualenv
- Activate the environment with $VENV/bin/activate
- Install any needed site-packages
- Run your Zope using the Python now at $VENV/bin/python
- 使用你的 Zope 的 Python,创建一个新的 virtualenv,有或没有 --no-site-packages
- 将您的 Zope 放入 virtualenv
- 使用 $VENV/bin/activate 激活环境
- 安装任何需要的站点包
- 现在在 $VENV/bin/python 使用 Python 运行你的 Zope
This has worked brilliantly for managing Django projects with various versions of Python, Django, and add-ons.
这对于使用各种版本的 Python、Django 和附加组件管理 Django 项目非常有效。
This articleseems to go into more detail on the specifics of Grok and Virtualenv, but the generalities should apply to Zope as welll.
这篇文章似乎更详细地介绍了 Grok 和 Virtualenv 的细节,但一般性也应该适用于 Zope。
回答by Jon Hadley
+1 for virtualenv.
+1 为 virtualenv。
Even if you don't need different Python versions, it's still good to keep your development dependencies seperate from your system Python.
即使您不需要不同的 Python 版本,将您的开发依赖项与系统 Python 分开仍然很好。
I'm not sure what OS you are using, but I find theseinstructions very useful for getting python development environments running on OSX.
我不确定您使用的是什么操作系统,但我发现这些说明对于让 Python 开发环境在 OSX 上运行非常有用。
回答by sebasgo
The approach I prefer which should work on every UNIX-like operating system:
我更喜欢的方法应该适用于每个类 UNIX 操作系统:
Create for each application which need an specific python version an user account. Install in each user count the corresponding python version with an user-local prefix (like ~/build/python) and add ~/build/bin/ to the PATH environment variable of the user. Install/use your python applications in their correct user.
为每个需要特定 python 版本的应用程序创建一个用户帐户。在每个用户中安装带有用户本地前缀(如 ~/build/python)的相应 python 版本,并将 ~/build/bin/ 添加到用户的 PATH 环境变量中。在正确的用户中安装/使用您的 python 应用程序。
The advantage of this approach is the perfect isolation between the individual python installations and relatively convenient selection of the correct python environment (just su
to the appropriate user). Also the operating system remains untouched.
这种方法的优点是在各个 python 安装之间完美隔离,并且相对方便地选择正确的 python 环境(只su
针对合适的用户)。此外,操作系统保持不变。