Python and Universal Binaries on Mac OS X
It's been a pretty long haul getting Python to do the right thing on Mac OS X with regard to Universal Binaries. The dust is settling, and it's about time to start publicizing the results.
In order to compile extensions with Universal MacPython, you absolutely must have the latest version of Xcode installed. When you install it, make absolutely sure that you Customize the installation and install the Mac OS X 10.4 Universal SDK. Universal MacPython requires this SDK to be installed, as it instructs the compiler and linker to use this specific SDK. There is a hook that will remove these special flags, but ONLY for legacy Mac OS X 10.3.9 users. Mac OS X 10.3.9 users should still be able to compile extensions, but the resultant binaries will be PPC only and shouldn't be distributed (as they will not work on Intel).
Besides the obvious endian fixes and distutils/configure hackery, Universal MacPython includes many usability enhancements over previous distributions of Python for Mac OS X:
- IDLE, the Python IDE, should now ship with Mac keybindings and menus by default
- Placing binaries in /usr/local/bin is now optional
- The bin directory from the framework is now (by default) automatically added first to your PATH environment variable. This means that when you open a new terminal session and type python, you will get Universal Python 2.4.3. Yes, it's ugly to do this, but it's a necessary evil. PATH related issues are by far the most frequent source of confusion on pythonmac-sig (between Python itself and distutils-installed scripts), and this is the solution. darwinports does something quite similar.
- pythonw is now an executable, instead of a shell script, so it may be used directly in a hash-bang line for a shell script (#!).
- Users no longer need to know or care about pythonw. python and pythonw are the same binary, which simply does an execve to a Python executable inside of a "fake" application bundle to placate the WindowServer. Yes, this introduces a tiny little bit of overhead when invoking python due to the extra syscall, but it is again a necessary evil to work around a design flaw in Mac OS X.
- Includes a working bsddb, readline, and curses.
- Known compatible with Mac OS X 10.3.9 and later, without any patching necessary on Mac OS X 10.4.
The latest Universal Python source code is currently a fork of Python 2.4.3, and currently resides outside of the official Python subversion repository. For those interested in the source, it is here:
The latest binary release of Universal Python is currently available in the Universal Python 2.4 section of pythonmac.org packages! There is/was an older Universal Python build available somewhere on python.org but it is NOT what you should be using (it's built without compiler optimization and is roughly 50% slower on either architecture!):
PyObjC and py2app users with Universal MacPython should install PyObjC from SVN trunk (which will net you a universal-ready py2app). There is currently no tagged release of either project that is suitable for this build of Python, but we hope to fix that soon:
- http://svn.red-bean.com/pyobjc/trunk/pyobjc/
- http://svn.red-bean.com/bob/py2app/branches/py2app-0.2-maint/
pythonmac.org packages has been split into two sections, one for universal packages, and one for legacy builds of Python. Currently there aren't many universal packages ready (largely because I don't have an Intel machine yet, so I can only test on PPC). The legacy packages for Python 2.4 are still compatible with Universal MacPython, however, they are NOT compatible with Intel.
Most packages should compile just fine, and setuptools/easy_install are already Universal MacPython aware. However, packages that depend on external libraries will not compile correctly of the dependent libraries aren't also Universal. This means that MySQL bindings, wxPython, and a few other popular packages are not yet readily available. This issue will resolve itself at some point due to the demand, but it's not resolved yet. There's a list of desired packages and their status at the UniversalPackages node on the pythonmac.org wiki.
Thank you.
Python and mac developers (especially the subset who are both) greatly appreciate this work. Great job!
Comment by js — 2006-04-10 @ 10:05 pm
Any chance that Python 2.5 and PyObjC will make it into Leopard?
Comment by Jacob — 2006-04-11 @ 1:14 pm
How am I supposed to know? I wouldn’t be able to answer that question even if I did. Surely we’ll all know in a few months, after WWDC.
Personally I don’t give a damn what Python Apple ships because I’m always going to need to install another. Vendor shipped software is never usable for creating self-contained redistributable applications anyway. Apple does not guarantee backwards compatibility outside of their own libraries. Depending on the vendor Python is a sure-fire way to get a load of user complaints whenever Apple happens to change minor versions of Python across a Mac OS X release.
I highly doubt we’ll see Python 2.5 in Leopard given the release schedule of Python and my best guess for Leopard. I’d recommend that they just derive something from our universal fork of 2.4.3. PyObjC would be convenient to have around though, file a radar if you want to see it make Leopard.
Comment by bob — 2006-04-11 @ 4:11 pm
Many thanks for this Bob, I expect to pick up my MacBookPro tomorrow and universal MacPython is going to be one of the first things I install.
Cheers,
Tone
Comment by Tony — 2006-04-30 @ 11:37 pm
Actually the latest version of the universal build of python is 2.5 and can be downloaded from the python.org website. As it is just released there are little or no binary packages for 3th-party software available. There are also some compatibility issues with some 3th-party software due to the changes from 2.4 to 2.5, Pyrex is one if the affected packages.
BTW. 2.5 is also the one with the best looking IDLE for OSX and has bindings to .py files, which means you can double-click on .py files to open them in IDLE (although you might have to change your launcher preferences for that, for some reason PythonLauncher stays the prefered “editor” for .py files.
Comment by Ronald Oussoren — 2006-09-20 @ 3:23 am