macos 在 Mac 上将 Python 升级到 2.6

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

Upgrade Python to 2.6 on Mac

pythonmacosinstallationupgrade

提问by eozzy

I'd like to upgrade the default python installation (2.5.1) supplied with OS X Leopard to the latest version. Please let me know how I can achieve this.

我想将 OS X Leopard 提供的默认 python 安装 (2.5.1) 升级到最新版本。请让我知道我如何实现这一目标。

Thanks

谢谢

采纳答案by Sridhar Ratnakumar

Don't upgrade.

不要升级。

  1. Install ActivePython(which co-existswith others).
  2. Open Terminal
  3. Type python2.6
  1. 安装ActivePython(与其他人共存)。
  2. 打开终端
  3. 类型 python2.6

回答by Alex Martelli

When an OS is distributed with some specific Python release and uses it for some OS functionality (as is the case with Mac OS X, as well as many Linux distros &c), you should nottamper in any way with the system-supplied Python (as in, "upgrading" it and the like): while Python strives for backwards compatibility within any major release (such as 2.*or 3.*, this can never be 100% guaranted; your OS supplied tested all functionality thoroughly with the specific Python version they distribute; if you manage to alter that version, "on your head be it" -- neither your OS supplier nor the PSF accepts any responsibility for whatever damage that might perhaps do to your system.

当OS是同某些特定的Python版本,并使用它的一些操作系统的功能(如与Mac OS X,以及许多Linux发行版&C的情况下),你应该不会在系统提供的Python任何方式篡改(例如,“升级”它等):虽然 Python 力求在任何主要版本中向后兼容(例如2.*3.*,这永远不能100% 保证;您提供的操作系统已使用它们分发的特定 Python 版本彻底测试了所有功能;如果您设法更改该版本,“由您自己决定”——您的操作系统供应商和 PSF 均不对可能对您的系统造成的任何损害承担任何责任。

Rather, as other answers already suggested, install any other release you wish "besides" the system one -- why tamper with that crucial one, and risk breaking things, when installing others is so easy anyway?! On typical Mac OS X 10.5 machines (haven't upgraded any of my several macs to 10.6 yet), I have the Apple-supplied 2.5, a 2.4 on the side to support some old projects not worth the bother to upgrate, the latest 2.6 for new stuff, 3.1 as well to get the very newest -- they all live together in peace and quiet, I just type the release number explicitly, i.e. using python2.6at the prompt, when I want a specific release. What release gets used when at the shell prompt you just say pythonis up to you (I personally prefer that to mean "the system-supplied Python", but it's a matter of taste: by setting paths, or shell aliases, &c, you can make it mean whatever you wish).

相反,正如其他答案已经建议的那样,安装您希望“除了”系统版本之外的任何其他版本 - 为什么在安装其他版本如此简单的情况下篡改那个关键版本,并冒着破坏事物的风险?!在典型的 Mac OS X 10.5 机器上(还没有将我的几台 mac 中的任何一台升级到 10.6),我有 Apple 提供的 2.5,一边是 2.4,以支持一些不值得费心升级的旧项目,最新的 2.6对于新东西,3.1 也是最新的——它们都和平而安静地生活在一起,我只是明确输入版本号,即python2.6在我想要特定版本时在提示符下使用。在 shell 提示下您只说使用什么版本python取决于您(我个人更喜欢将其表示为“系统提供的 Python”,但这是一个品味问题:通过设置路径或 shell 别名,&c,您可以使其具有任何您希望的含义)。

回答by gahooa

May I suggest you leave the "Default" be, and install Python in /usr/local/bin.

我建议您保留“默认”,并在 /usr/local/bin 中安装 Python。

  1. Download python
  2. Unzip it
  3. ./configure
  4. make
  5. sudo make install
  1. 下载蟒蛇
  2. 解压
  3. 。/配置
  4. 制作
  5. 须藤制作安装

done.

完毕。

Since /usr/local/bin comes before /usr/bin in the $PATH, you will invoke 2.6 when you type python, but the OS will remain stable...

由于 /usr/local/bin 在 $PATH 中位于 /usr/bin 之前,因此您在键入 python 时将调用 2.6,但操作系统将保持稳定...

回答by Adam Rosenfield

You have a number of options

您有多种选择

  • Install with MacPortsor Fink, e.g.:

    sudo port install python2.6
    
  • Install from the disc image from python.org
  • Install from source:

    tar xzvf Python-2.6.3.tgz
    cd Python-2.6.3
    ./configure && make && sudo make install
    
  • 使用MacPortsFink安装,例如:

    sudo port install python2.6
    
  • python.org的光盘映像安装
  • 安装:

    tar xzvf Python-2.6.3.tgz
    cd Python-2.6.3
    ./configure && make && sudo make install
    

回答by Pedro Salgado

The best is to use macports(just like Adam Rosenfield stated on this thread).

最好的方法是使用macports(就像 Adam Rosenfield 在这个线程中所说的那样)。

You can easily switch between Python versions using macports select mechanism:

您可以使用 macports 选择机制轻松地在 Python 版本之间切换:

$ sudo port select --set python pythonXY

$ sudo port select --set python pythonXY

To view the list of available Python versions you can use above and/or confirm which one you're using:

要查看您可以在上面使用的可用 Python 版本列表和/或确认您使用的是哪个版本:

$ sudo port select --list python

$ sudo port select --list python

To install a new Python version:

要安装新的 Python 版本:

$ sudo port install pythonXY

$ sudo port install pythonXY

回答by Andrew Jaffe

The standard http://python.orginstall for Mac OSX will happily coexistwith the "system python". If you let the installer change your paths, when you run python from a prompt in terminal, it will find the version at

Mac OSX的标准http://python.org安装将与“系统 python”愉快地共存。如果您让安装程序更改您的路径,当您从终端的提示中运行 python 时,它会在以下位置找到版本

 /Library/Frameworks/Python.framework/Versions/2.6/bin/python

However, this won't interfere with anything that OSX itself does with python, which correctly hardwires the path to the version that it installs.

但是,这不会干扰 OSX 本身对 python 所做的任何事情,它正确地硬连线到它安装的版本的路径。

回答by Devin Ceartas

I believe there are a few options. The one I like is to install alternative UNIX software on my Macs using MacPorts, http://www.macports.org/-- this way the new software is installed in a different directory and won't mess up anything depending on the apple-installed version, and macports also has a nice way of keeping their installed software up to date. I believe MacPorts helps take care of dependencies as well.

我相信有几种选择。我喜欢的是使用 MacPorts,http://www.macports.org/在我的 Mac 上安装替代的 UNIX 软件——这样新软件安装在不同的目录中,并且不会根据苹果的不同而搞砸任何事情-installed 版本,并且 macports 也有一个很好的方式来保持他们安装的软件是最新的。我相信 MacPorts 也有助于处理依赖关系。