macos 如何更改 Mac Snow Leopard 中的默认 Python 版本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5752753/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 07:58:38  来源:igfitidea点击:

How do I change the default Python version in my Mac Snow Leopard?

pythonmacos

提问by user720129

How do I change the default Python version used in my Mac Snow Leopard? I'm trying to switch from v2.5 to v3.0

如何更改 Mac Snow Leopard 中使用的默认 Python 版本?我正在尝试从 v2.5 切换到 v3.0

回答by Andreas Jung

Is is not recommended to change the system Python installation on any system without any need. Better install Python 3.X in a different location and adjust your $PATH as needed. The Python installation may be needed for further functionality under the hood. So leave it as it is and install arbitrary Python interpreters in a different location. Macports and Brew will do that automatically. If you compile Python yourself:

不建议在没有任何需要的情况下在任何系统上更改系统 Python 安装。最好在不同的位置安装 Python 3.X 并根据需要调整 $PATH。可能需要安装 Python 以实现更多功能。所以保持原样并在不同的位置安装任意的 Python 解释器。Macports 和 Brew 将自动执行此操作。如果你自己编译 Python:

 configure --prefix=/path/to/my/python/installation.

回答by curious

You want to create a symlink to the desired version.

您想要创建指向所需版本的符号链接。

cd /Library/Frameworks/Python.framework/Versions
sudo rm Current
sudo ln -s /Library/Frameworks/Python.framework/Versions/3.0 Current

This removes the current pointer to your default Python version and sets it to your 3.0 version.

这将删除当前指向默认 Python 版本的指针并将其设置为您的 3.0 版本。

回答by Ned Deily

If you are reading the Apple-supplied Python man page (man python) on Mac OS X 10.6 (Snow Leopard), be aware that it is incorrect: Apple did not ship a Python 3.0 with 10.6. You'll need to install a Python 3 version yourself. The easiest way is to use a binary installer from python.org. But you can also use MacPorts or Homebrew or do it yourself. Also, be aware that support for Python 3.0 was dropped immediately with the release of Python 3.1. Python 3.2 is now current. However you install it, the Python 3 interpreter will be available as either python3or python3.2. It does not conflict with Python 2 (python). You may need to adjust your shell PATH though. The python.org installer will do that for you; follow the installation instructions.

如果您man python在 Mac OS X 10.6 (Snow Leopard) 上阅读 Apple 提供的 Python 手册页 ( ),请注意它是错误的:Apple 没有随 10.6 一起提供 Python 3.0。您需要自己安装 Python 3 版本。最简单的方法是使用来自 python.org二进制安装程序。但您也可以使用 MacPorts 或 Homebrew 或自己动手。另外,请注意,随着 Python 3.1 的发布,对 Python 3.0 的支持立即被删除。Python 3.2 现在是最新的。无论您如何安装它,Python 3 解释器都可以作为python3python3.2. 它与 Python 2 ( python)不冲突。不过,您可能需要调整 shell PATH。python.org 安装程序会为你做这件事;按照安装说明进行操作。

回答by Alex

Try the following: defaults write com.apple.versioner.python Version 3.2in a terminal. Assuming you have 3.2 installed of course.

尝试以下操作:defaults write com.apple.versioner.python Version 3.2在终端中。当然,假设您安装了 3.2。

EDIT: As Neil Deily points out in his comment this only works with Python distributions shipped by Apple.

编辑:正如 Neil Deily 在他的评论中指出的那样,这只适用于 Apple 提供的 Python 发行版。

回答by colin

I would first install Xcode on my machine (it comes on the installation disc that came with your computer). Then run Software Update to bring it up to date (at least to the most-current free version).

我会先在我的机器上安装 Xcode(它在您的计算机附带的安装光盘上)。然后运行软件更新以使其保持最新(至少是最新的免费版本)。

Then, download the Python 3.x source code and extract it. Do "./configure", "make" and "sudo make install" in that directory. These will install the new Python installation in /usr/local/bin (and other nearby places).

然后,下载 Python 3.x 源代码并解压。在该目录中执行“./configure”、“make”和“sudo make install”。这些将在 /usr/local/bin (和其他附近的地方)安装新的 Python 安装。

If all goes well, /usr/local/bin/python will be a Python 3 interpreter you can use. I would hesitate to overwrite the installed version of Python, since that might make trouble for python scripts shipped with the operating system. I never install anything in /usr; I let Software Update take care of that. For all the rest of my software needs, the "./configure ... make ... sudo make install" technique works very well on Snow Leopard once Xcode is installed.

如果一切顺利,/usr/local/bin/python 将成为您可以使用的 Python 3 解释器。我会犹豫是否覆盖已安装的 Python 版本,因为这可能会给操作系统附带的 Python 脚本带来麻烦。我从不在 /usr 中安装任何东西;我让软件更新来解决这个问题。对于我的所有其他软件需求,一旦安装了 Xcode,“./configure ... make ... sudo make install”技术在 Snow Leopard 上运行得非常好。