Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
Python 3.0 is out. Woo! Some people have been saying that they'd like to be able to run it alongside 2.6, 2.5, etc to test it out. Well, Python is actually designed for this. All you have to do is build it with make altinstall and that will give you a python3.0 binary without touching your default python binary. But on Mac OS X it's a little different.
First, there isn't a DMG installer available yet but there probably will be one soon. UPDATE: as of 3.0.1 a Mac OS X installer is available. However, building a Framework from source is pretty simple. You will need Apple Developer tools installed to get a C compiler. Then just download the Python source from above, and install on Mac OS X like:
$ cd ~/Downloads/Python-3.0/
$ ./configure --enable-framework MACOSX_DEPLOYMENT_TARGET=10.5 --with-universal-archs=all
$ export LC_CTYPE=en_US.UTF-8
$ make && make test
(UPDATE: see comments for some notes about this configure command, YMMV. Also, it is a little trickier to get readline to work, i.e. for command history in the interpreter. Chris Miles explains how to do this.)
After the tests pass, install with:
$ sudo make frameworkinstall
But ... you're not done. There isn't an altframeworkinstall target so you will be overwriting your default python binary. The fix for this is easy:
$ cd /Library/Frameworks/Python.framework/Versions/
$ ls -l
total 8
drwxrwxr-x 10 root admin 340 Nov 10 14:47 2.4
drwxrwxr-x 10 root admin 340 Feb 22 2008 2.5
drwxrwxr-x 10 root admin 340 Oct 1 18:52 2.6
drwxr-xr-x 10 root admin 340 Dec 5 11:33 3.0
lrwxr-xr-x 1 root admin 3 Dec 5 11:34 Current -> 3.0
$ sudo rm Current
$ sudo ln -s 2.5 Current
$ ls -l
total 8
drwxrwxr-x 10 root admin 340 Nov 10 14:47 2.4
drwxrwxr-x 10 root admin 340 Feb 22 2008 2.5
drwxrwxr-x 10 root admin 340 Oct 1 18:52 2.6
drwxr-xr-x 10 root admin 340 Dec 5 11:33 3.0
lrwxr-xr-x 1 root admin 3 Dec 5 11:34 Current -> 2.5
NOTE: If you haven't ever installed Python yourself then you might be using the default Apple Python which for some crazy reason is located in /System/Library/Frameworks/Python.framework/Versions. Be sure to adjust the Current symlink appropriately.
Open a new shell and type python -V. It should be 2.5 or whatever you set it to. Phew! The only other step is to modify your .bash_profile or the equivalent for the new bin path. Be sure it does not override your other Python paths. Mine looks like this (note: 2.5 is Current):
PATH="/Library/Frameworks/Python.framework/Versions/3.0/bin:${PATH}"
PATH="/Library/Frameworks/Python.framework/Versions/2.4/bin:${PATH}"
PATH="/Library/Frameworks/Python.framework/Versions/2.6/bin:${PATH}"
PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}"
export PATH
Now you can type python3.0 and you'll be in a 3.0 shell. What do you next? Hrm, there's not much to do in 3.0 yet. You could experiment with the 2to3 script on some of your favorite modules :)

Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Graham Dumpleton on Friday Dec 5th, 2008 at 5:31p.m.
Note that that will only build for 32 bit. This will mean it isn't usable if want to use it in an application that links the Python framework and runs it as 64 bit, such as with mod_wsgi under MacOS X supplied version of Apache. If needing 64 bit support as well for the Python framework, you need to build for all architectures. After a few problems, the configure line that seemed to work for that was as follows.
./configure --enable-framework --enable-universalsdk=/ MACOSX_DEPLOYMENT_TARGET=10.5 --with-universal-archs=all
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Kumar McMillan on Friday Dec 5th, 2008 at 5:55p.m.
hrmm, interesting. I did make clean and tried this configure setting. Everything built but I got a segfault in the tests after test_dbm.
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Kumar McMillan on Friday Dec 5th, 2008 at 6:10p.m.
I changed it to:
./configure --enable-framework MACOSX_DEPLOYMENT_TARGET=10.5 --with-universal-archs=all
and that got all tests to pass for me, no segfaults.
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Christian Heimes on Friday Dec 5th, 2008 at 7:06p.m.
I've added a feature request for you: http://bugs.python.org/issue4554. A patch is welcome, too :)
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Noah Gift on Saturday Dec 6th, 2008 at 6:32p.m.
Personally, I like the build script. This is what I used with Python2.6
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Kumar McMillan on Saturday Dec 6th, 2008 at 6:38p.m.
There is a build script for this already?
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Delsvr on Sunday Dec 7th, 2008 at 6:52p.m.
On make frameworkinstall, I'm getting this error:
lipo -extract i386 -extract ppc7400 -output "/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python-32" "/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python"
lipo: input file (/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python) must be a fat file when the -extract option is specified
make[1]: *** [install_Python4way] Error 1
make: *** [frameworkinstallapps4way] Error 2
Any ideas? This is the first time I'm installing Python. Thanks.
BTW, stumbled on your blog thanks to a Google search. Nice stuff.
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Kumar McMillan on Sunday Dec 7th, 2008 at 7:27p.m.
huh, never seen that. However, it looks like you are installing 2.6? These instructions are for 3.0. Although theoretically it should work for 2.6 too :/
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Michael Foord on Monday Dec 8th, 2008 at 7:32a.m.
Thanks - works great for me, much appreciated.
Michael
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by ovi on Monday Dec 8th, 2008 at 10:37a.m.
thanks a mill... it works like a charm
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by .:. brainsik on Monday Dec 8th, 2008 at 6:50p.m.
My solution: wait for it to appear in MacPorts. ;-)
They are usually pretty quick to get things in there -- 2.6.1 is already available -- so I'm hoping 3.0 will show up soon.
That said, I know they are in the middle of getting their next big release out...
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Kumar McMillan on Monday Dec 8th, 2008 at 8:02p.m.
I use MacPorts for everything *except* Python. The reason I don't like ports for Python is it installs into /opt/local so if you ever use a DMG from python.org for a point release upgrade then you lose any modules you installed with ports. Plus, easy_install is just as easy as port install py-... so I don't miss it much.
In dire situations where a python module requires a bunch of c libs, I read the port file and use ports for all the dependencies, then resort to python setup.py install with all the include paths point to /opt/local/.../
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Steve Klass on Wednesday Dec 10th, 2008 at 8:03p.m.
FWIW - Grahams suggestion does NOT enable 64-bit executable python.
> file python
python: Mach-O executable i386
I thought if it was 64 bit it would have said - Mach-O 64-bit executable x86_64 (per http://velocipeek.com/2007/10/30/os-x-leopard-test-drive-part-2/) Even setting --with-universal-archs=64-bit made no difference.
Couple other comments - obviously readline support and gbdm support is not included.
Make sure the /usr/local/bin/install is not used - PATH may need to be adjusted - You will error out.
Also if you fail test_cmd_line make sure you look at this known bug - but I couldn't seem to get it to pass (No amount of env LANG= seemed to work..
http://bugs.python.org/issue4388
All other tests passed..
Great stuff - Keep up the good work!!
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by angus on Saturday Dec 20th, 2008 at 6:04p.m.
Thanks for this tutorial! I'm kind of new to all of this and was wondering if it is possible to get syntax highlighting within the terminal for python 3.0? I doubt it, but that would be cool
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Kumar McMillan on Saturday Dec 20th, 2008 at 6:31p.m.
IPython might do syntax highlighting: http://ipython.scipy.org/moin/
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Xavier on Wednesday Dec 24th, 2008 at 6:52p.m.
For the error 1 issue at make stage you have to do first a
export LC_CTYPE=en_US.UTF-8
It worked for me.
But I now have a new problem, cursor keys (arrows up/down/...) are not working (up key is returning ^[[A for example). So I can't go up through the history in the python terminal which is very annoying.
Any help would be much appreciated!
Thanks! :-)
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Kumar McMillan on Wednesday Dec 24th, 2008 at 11:55p.m.
I keep that LC_TYPE command in my bash_profile so I forgot to mention it (updated the post, thanks).
As for the shell history, the readline module is not installed. Hmm, I tried re-configuring with --enable-readline=/opt/local/include/readline as a guess but that didn't activate the readline module.
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Xavier on Thursday Dec 25th, 2008 at 3:59a.m.
For the error 1 issue at make stage you have to do first a
export LC_CTYPE=en_US.UTF-8
It worked for me.
But I now have a new problem, cursor keys (arrows up/down/...) are not working (up key is returning ^[[A for example). So I can't go up through the history in the python terminal which is very annoying.
Any help would be much appreciated!
Thanks! :-)
problems with compiling python3.0
posted by cerebus on Friday Dec 26th, 2008 at 11:53a.m.
Hi to all you, I have kind of a big problem and would really appricate if you could help me..
I tried to compile python3.0 from source with the usuall ./configure
-make
and then he tells me that bits are missing for the _gdbm, ossaudiodev, readline, spwd modules and that i should locate them with setup.py and so on.
I already know this problem from my ubuntu-netbook, I need these stupid libraries and got them from the ubuntu channel (all except one, which really annoys me!!)
So where do I get them for macOsX?
PLZ HELP!
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Kumar McMillan on Friday Dec 26th, 2008 at 2:50p.m.
cerebus, I don't know much about these libs. I'd suggest asking on IRC or one of the mailing lists over at http://wiki.python.org/moin/MacPython
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by anglyan on Tuesday Jan 13th, 2009 at 10:19p.m.
Hi!
First of all, thanks for the tips. However, I found a conflict with pydoc. I wasn't careful enough updating the system path and I was invoking in the terminal the 3.0 version instead of the 2.6 version. Easy to solve, but nevertheless annoying.
Cheers,
A.
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Sherry Prow on Thursday Jan 15th, 2009 at 12:10p.m.
Thanks for the handy install instructions. It worked perfectly for me. But how do I uninstall? Any ideas? I know enough unix to be dangerous.
Thanks,
S.
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Kumar McMillan on Thursday Jan 15th, 2009 at 12:51p.m.
Hi Sherry.
The directories python installs into are self-contained. So you can simply delete (as root) /Library/Frameworks/Python.framework/Versions/3.0/ and you will no longer have Python 3.0 on your machine. After doing so, you should double check that the Current symlink is pointing to an active installation of Python if you still want an older version to work.
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Kumar McMillan on Thursday Jan 15th, 2009 at 1:00p.m.
cerebus, Chris Miles explains how to install readline and the other modules you were asking about: http://chrismiles.livejournal.com/25648.html
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by crap on Thursday Jan 15th, 2009 at 4:11p.m.
fuck this
configure: error: no acceptable C compiler found in $PATH
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Kumar McMillan on Thursday Jan 15th, 2009 at 4:42p.m.
Dear Crap, you need Apple Developer tools installed to compile anything on OS X. I will update the post.
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Cris on Sunday Feb 15th, 2009 at 6:47a.m.
Really dumb question. This is my first time trying to install anything outside of a drive image/drag and drop. Why would I, as the computer admin, be 'not allowed to execute' the sudo make frameworkinstall?
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Ned Deily on Sunday Feb 15th, 2009 at 9:33p.m.
FYI, Python 3.0.1 has just been released and an official installer for OS X is now available here:
http://www.python.org/download/releases/3.0.1/
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Kumar McMillan on Sunday Feb 15th, 2009 at 11:06p.m.
Thanks, Ned. Updated.
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Anthony Smith on Saturday Feb 28th, 2009 at 1:41a.m.
Has anybody been successful in building Python 3.0.1? Using the instructions here I get an error for test_osx_env.
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Anthony Smith on Saturday Feb 28th, 2009 at 1:43a.m.
More info:
test_osx_env
Could not find platform independent libraries
Could not find platform dependent libraries
Consider setting $PYTHONHOME to [:]
Fatal Python error: Py_Initialize: can't initialize sys standard streams
ImportError: No module named encodings.utf_8
test test_osx_env failed -- Traceback (most recent call last):
File "/Users/anthonysmith/Downloads/Python-3.0.1/Lib/test/test_osx_env.py", line 27, in test_pythonexecutable_sets_sys_executable
self._check_sys('PYTHONEXECUTABLE', '==', 'sys.executable')
File "/Users/anthonysmith/Downloads/Python-3.0.1/Lib/test/test_osx_env.py", line 24, in _check_sys
self.assertEqual(rc, 2, "expected %s %s %s" % (ev, cond, sv))
AssertionError: expected PYTHONEXECUTABLE == sys.executable
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Dan on Wednesday Mar 18th, 2009 at 1:29p.m.
Hi all. I installed python 3.0.1 using the official installer. now when i type python in my terminal, it's python 3.0.1. is my older python still there, and if so, how do i use that?
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Kumar McMillan on Wednesday Mar 18th, 2009 at 4:05p.m.
Dan, just skip to the section in this article about linking your 2.5 or 2.5 install dir to Current. Basically:
cd /Library/Frameworks/Python.framework/Versions/
sudo rm Current
sudo ln -s 2.5 Current
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Dan on Thursday Mar 19th, 2009 at 8:55a.m.
Thanks Kumar. I had also installed the 2.6 mac installer (so i guess there's 2.5, 2.6 and 3.0.1?) all on my machine. can i do this for 2.6 as well?
Also, i noticed that since i've been mucking around with these python installers, my Xcode will no longer run... ("The application Xcode quit unexpectedly"). Any ideas what happened?
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Kumar McMillan on Thursday Mar 19th, 2009 at 10:02a.m.
You can have as many multiple pythons installed as you want. Just symlink Current to the one that you want to start up when you type `python`. You can start up the others with python3.0 python2.6, python2.7 etc.
As for xcode, yikes, no idea. It's possible that xcode was using the system python for something but if so then it would be misbehaving if it did not use the hardcoded path which is something in /System/Library/Frameworks/Python.framework/...
I'd recommend taking a look in /var/log/system.log to see what the exact error is. Or read the crash report, which gets saved to some file in ~/Library/Logs/CrashReporter/
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Kali on Wednesday Apr 15th, 2009 at 6:21p.m.
I do not understand this instruction:
PATH="/Library/Frameworks/Python.framework/Versions/3.0/bin:${PATH}"
PATH="/Library/Frameworks/Python.framework/Versions/2.4/bin:${PATH}"
PATH="/Library/Frameworks/Python.framework/Versions/2.6/bin:${PATH}"
PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}"
export PATH
How can I actually modify my .bash_profile using the terminal or which is the file i'm supposed to change.
Thanks in advance! awesome tutorial!.
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Kumar McMillan on Wednesday Apr 15th, 2009 at 9:26p.m.
you just need to open ~/.bash_profile in a text editor and edit it there.
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Thabo on Friday Jun 26th, 2009 at 2:06p.m.
Hi All,
I am trying to install python 3.0.1 (from Python-3.0.1.tar) on my new mac book pro by following the instructions given on this page.
make && make test give me the following error :
2 tests failed:
test_cmath test_osx_env
22 tests skipped:
test_codecmaps_cn test_codecmaps_hk test_codecmaps_jp
test_codecmaps_kr test_codecmaps_tw test_curses test_dbm_gnu
test_epoll test_largefile test_nis test_normalization
test_ossaudiodev test_pep277 test_socketserver test_startfile
test_timeout test_urllib2net test_urllibnet test_winreg
test_winsound test_xmlrpc_net test_zipfile64
Those skips are all expected on darwin.
make: *** [test] Error 1
I guess skips are fine for the moment.
What about the make (test) error?
I tried to install the 3.0.1. dmg then the apples python and this python are in two different places as mentioned at the beginning of this article : pre installed is in /System/Library....... and the dmg gets installed in /Library/..........
Changing current doesnt change anything.
What should I do to get rid of this error and successfully install it.
Any help is welcome.
Cheers,
Thabo
Re: Python 3.0 On Mac OS X (alongside 2.6, 2.5, etc)
posted by Kumar McMillan on Friday Jun 26th, 2009 at 5:27p.m.
I'm not sure what's going on but it sounds like the paths aren't right. I'd suggest running `which python` and use that path to figure out which symlink to change.