为什么我的 Snow Leopard 在 /usr/bin 中安装了这么多 Python?是什么决定了哪一个是系统Python?

发布于 2024-09-17 00:40:59 字数 153 浏览 3 评论 0原文

为什么我的 Snow Leopard 在 /usr/bin 中安装了这么多 Python?是什么决定了哪一个是系统Python?

当我简单地输入“python”时,它是2.6.1〜但这似乎不是“System Python”,为什么不呢?如何改变Python系统以及有哪些缺点?

Why is there so many Pythons installed in /usr/bin for my Snow Leopard? What decides which one is the System Python?

When I simply type "python" it is 2.6.1 ~ but this doesn't seem to be the "System Python", why not? How does one change system Python and what are the drawbacks?

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

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

发布评论

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

评论(1

檐上三寸雪 2024-09-24 00:41:00

我的雪豹只安装了python 2.5和2.6,所以数量不是很多。您可能安装了其他 python(即 python3.0),可以在系统范围内(在 /usr/bin/ 中)或通过 macports (/opt/local)。

默认系统python是通过设置定义的,

defaults write com.apple.versioner.python Version 2.5

将默认值更改为2.5。您还可以使用环境变量,即对于 bash:

export VERSIONER_PYTHON_VERSION=2.5

所有这些都记录在 python 手册页中,

man python

总的来说,最好不要更改系统默认值。这是 OSX 可能依赖的某些脚本,并且您永远不知道这些脚本在不同版本上是否按预期工作。尤其是Python 3 不同,可能真的会破坏你的整个系统。

如果您希望为自己的脚本使用不同的 python,请

  1. 使用 virtualenv(总是好的)
  2. 更改您的 PATH 并确保您首选的 python 包含在 /usr/sbin 之前
  3. 明确地,使用 /my/preferred 调用脚本/Python

My snow leopard only has python 2.5 and 2.6 installed, so it's not that many. You may have additional pythons installed (i.e. python3.0), either system wide (in /usr/bin/) or through macports (/opt/local).

The default system python is defined through a setting,

defaults write com.apple.versioner.python Version 2.5

will change the default to 2.5. You can also use an environment variable, i.e. for bash:

export VERSIONER_PYTHON_VERSION=2.5

All of this is documented in the python manpage,

man python

Overall, it's better not to change the system default. It's what OSX may depend on for certain scripts, and you never know if these scripts work as expected on different versions. Especially Python 3 is different, and may really break your whole system.

If you want a different python to be used for your own scripts, either

  1. Use virtualenv (always good)
  2. Change your PATH and make sure your preferred python is included before the /usr/sbin one
  3. Be explicit, invoke the script using /my/preferred/python
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文