简体   繁体   English

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

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

How do I change the default Python version used in my Mac Snow Leopard? 如何更改Mac Snow Leopard中使用的默认Python版本? I'm trying to switch from v2.5 to v3.0 我正在尝试从v2.5切换到v3.0

Is is not recommended to change the system Python installation on any system without any need. 不建议不要在任何系统上更改系统Python安装。 Better install Python 3.X in a different location and adjust your $PATH as needed. 最好在不同的位置安装Python 3.X并根据需要调整$ PATH。 The Python installation may be needed for further functionality under the hood. 可能需要Python安装以获得更多功能。 So leave it as it is and install arbitrary Python interpreters in a different location. 所以保持原样,并在不同的位置安装任意Python解释器。 Macports and Brew will do that automatically. Macports和Brew会自动完成。 If you compile Python yourself: 如果您自己编译Python:

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

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版本。

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. 如果您正在Mac OS X 10.6(Snow Leopard)上阅读Apple提供的Python手册页( man python ),请注意它是不正确的:Apple没有发布带有10.6的Python 3.0。 You'll need to install a Python 3 version yourself. 您需要自己安装Python 3版本。 The easiest way is to use a binary installer from python.org . 最简单的方法是使用python.org中二进制安装程序 But you can also use MacPorts or Homebrew or do it yourself. 但您也可以使用MacPorts或Homebrew或自己动手。 Also, be aware that support for Python 3.0 was dropped immediately with the release of Python 3.1. 另外,请注意,随着Python 3.1的发布,对Python 3.0的支持立即被删除。 Python 3.2 is now current. Python 3.2现在是最新的。 However you install it, the Python 3 interpreter will be available as either python3 or python3.2 . 无论你安装它,Python 3解释器将以python3python3.2 It does not conflict with Python 2 ( python ). 它与Python 2( python )没有冲突。 You may need to adjust your shell PATH though. 您可能需要调整shell PATH。 The python.org installer will do that for you; python.org安装程序将为您完成此操作; follow the installation instructions. 按照安装说明进行操作

Try the following: defaults write com.apple.versioner.python Version 3.2 in a terminal. 请尝试以下操作: defaults write com.apple.versioner.python Version 3.2在终端中defaults write com.apple.versioner.python Version 3.2 Assuming you have 3.2 installed of course. 假设你当然安装了3.2。

EDIT: As Neil Deily points out in his comment this only works with Python distributions shipped by Apple. 编辑:正如Neil Deily在他的评论中指出的那样,这只适用于Apple发布的Python发行版。

I would first install Xcode on my machine (it comes on the installation disc that came with your computer). 我首先在我的机器上安装Xcode(它出现在你的计算机附带的安装光盘上)。 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. 然后,下载Python 3.x源代码并将其解压缩。 Do "./configure", "make" and "sudo make install" in that directory. 在该目录中执行“./configure”,“make”和“sudo make install”。 These will install the new Python installation in /usr/local/bin (and other nearby places). 这些将在/ usr / local / bin(以及附近的其他地方)安装新的Python安装。

If all goes well, /usr/local/bin/python will be a Python 3 interpreter you can use. 如果一切顺利,/ usr / local / bin / python将是您可以使用的Python 3解释器。 I would hesitate to overwrite the installed version of Python, since that might make trouble for python scripts shipped with the operating system. 我会犹豫是否覆盖已安装的Python版本,因为这可能会给操作系统附带的python脚本带来麻烦。 I never install anything in /usr; 我从不在/ 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. 对于我的所有其他软件需求,一旦安装了Xcode,“./configure ... make ... sudo make install”技术在Snow Leopard上运行得非常好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 与Mac OS X Snow Leopard一起发售的Python版本? - Python version shipping with Mac OS X Snow Leopard? 在OSX Snow Leopard上安装IPython以使用非默认的python版本(即python2.6.6 / python2.7) - Installing IPython to work with a non-default python version (i.e python2.6.6/python2.7) on OSX Snow Leopard 如何在Snow Leopard上将已编译的Python 2.6.4恢复为系统默认值? - How to revert compiled Python 2.6.4 to system default on Snow Leopard? Python - 在Mac OSX Snow Leopard中安装matplotlib - Python - Installing matplotlib in Mac OSX Snow Leopard 如何从OSX(雪豹)手动卸载PIL - How do I manually uninstall PIL from OSX (snow leopard) 如何在Snow Leopard中使用Python捕获iSight帧? - How can I capture iSight frames with Python in Snow Leopard? 如何在雪豹上安装多个python版本? - how to install multiple python versions on snow leopard? Snow Leopard上的Python,如何打开> 255个套接字? - Python on Snow Leopard, how to open >255 sockets? 在Mac Snow Leopard上玩系统python和python 27的问题 - Problems juggling system python and python 27 on Mac Snow Leopard 如何在Snow Leopard和其他32位/ 64位问题上强制Python为32位 - How do I force Python to be 32-bit on Snow Leopard and other 32-bit/64-bit questions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM