It’s easy:
defaults write com.apple.versioner.python Version 2.6
See man python
for a complete explanation from Apple.
Also, one gotcha: make sure you are running the Python that came with your computer and not some other one that you installed. Do this by typing which python
at your command prompt. It should point to /usr/bin/python
. I only mention this because my default is 2.6 under Snow Leopard (it was 2.5 when I was using Leopard). So the fact that you are getting 2.5 may indicate that there’s something else in your path.
Update
To address comments below:
This doesn’t do what people are asking.
It does for me, in OS X 10.8.2. After doing defaults write com.apple.versioner.python Version 2.6
, the default version of Python is indeed 2.6. (And likewise after changing back to 2.7.)
This is true whether I run python
directly, or use an executable script starting with #!/usr/bin/env python
—I get the expected version of Python.
This does not solve the symlink in /System/Library/Frameworks/Python.framework/Versions where Current point to 2.7 which may cause problems (because it is still in the sys.path with 2.6 !)
Indeed, it doesn’t fix that symlink.
However, run a short script that print()
s the sys.path
and (at least on my relatively default setup) the 2.6 library directories are on the path and the 2.7 dirs are not on the path. Nor is the Current
symlinked directory on the path. So it should not be a problem for most scripts.
However, it’s possible—haven’t tested—that the Current
symlink is used by either easy_install
or pip
. That would cause problems. It sure does seem like a bug that the symlink isn’t updated when you update the Python version.
@SBSTN I've got the same problem (python path pointing to
/Library/Frameworks/Python.framework/Versions/Current/bin
) How do I change this? – Zach – 2011-03-20T20:56:12.677Doesn't work with Xcode4 as there's no /Library/Frameworks/Python* anymore nor does /usr/bin/python point anywhere else. Any ideas? MacPorts would be a solutions but I don't want to install it. – Alex – 2011-05-11T08:27:14.680
I’ve installed Xcode 4 and it still works as described.
/usr/bin/python
is an executable, not a link./usr/bin/python2.6
is a link that points to../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
. Given that the Python executable is in/System/Library
it should be available regardless of whether/what version of Xcode is installed. – Nate – 2011-05-11T23:52:16.1803You were right. I had a long time ago installed MacPython and that screwed up my PATH variable so
python
pointed to/Library/Frameworks/Python.framework/Versions/Current/bin
. Naturally that didn't get upgraded to 2.6. So I replaced my PATH variable with the default one I found on Google, and will now remove MacPython from my system. – SBSTN – 2009-09-04T10:14:05.683This doesn't do what people are asking. Not sure why it's the answer. – 010110110101 – 2012-01-17T02:49:58.147
This does not solve the symlink in
/System/Library/Frameworks/Python.framework/Versions
whereCurrent
point to2.7
which may cause problems (because it is still in thesys.path
with 2.6 !) – Stan – 2012-10-02T12:24:39.890@Stan: On my system,
Current
is not on thesys.path
, on a stock installation of 10.8. – Nate – 2012-10-08T17:45:02.637