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

发布于 2024-11-02 13:11:18 字数 66 浏览 1 评论 0原文

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

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

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

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

发布评论

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

评论(5

不喜欢何必死缠烂打 2024-11-09 13:11:18

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

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

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:

 configure --prefix=/path/to/my/python/installation.
柳若烟 2024-11-09 13:11:18

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

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

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

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.

谁人与我共长歌 2024-11-09 13:11:18

如果您正在 Mac OS X 10.6 (Snow Leopard) 上阅读 Apple 提供的 Python 手册页 (man 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 路径。 python.org 安装程序将为您完成此操作;请按照安装说明进行操作。

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 python3 or 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.

二智少女猫性小仙女 2024-11-09 13:11:18

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

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

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

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

挽清梦 2024-11-09 13:11:18

我首先会在我的机器上安装 Xcode(它位于计算机附带的安装光盘上)。然后运行软件更新以将其更新到最新(至少到最新的免费版本)。

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

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

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).

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).

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.

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