简体   繁体   中英

How can I make python 2.6 my default in Mac OS X Lion?

I just upgraded to lion and with it came Python 2.7. I need to use 2.6 as my default python as the project I primarily work on uses 2.6.

Apple has provided two very simple ways to change the default python on OS X 10.6 Snow Leopard and 10.7 Lion. It's all detailed in the Apple man page for python(1):

$ man python
$ which python
/usr/bin/python
$ python -V
Python 2.7.1
#
# temporarily change version
#
$ export VERSIONER_PYTHON_VERSION=2.6
$ python -V
Python 2.6.6
$ unset VERSIONER_PYTHON_VERSION
$ python -V
Python 2.7.1
#
# persistently change version
#
$ defaults write com.apple.versioner.python Version 2.6
$ python -V
Python 2.6.6

After running the following:

defaults write com.apple.versioner.python Version 2.6

To make sure the packages you install with 'sudo' are installed for the correct Python version, also set the versioner option as a superuser:

sudo su
# Enter password
defaults write com.apple.versioner.python Version 2.6
exit

You have a few options:

  1. Change /usr/bin/python to a link to /usr/bin/python2.6
  2. Put /System/Library/Frameworks/Python.framework/Versions/2.6/bin in your path before /usr/bin
  3. Explicitly tell your scripts to use /usr/bin/python2.6

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM