Friday, October 02, 2009

Snow Leopard Python 32-bit Script

With the release of Snow Leopard Apple has made good by making a big switch in the core applications to 64-bit. You can read all about it. How they shrunk the size of them, made them quicker, etc. iTunes however is still 32 :( Not that it really matters.

One that has mattered for me however is Python. Snow Leopard comes with Python 2.6 instead of 2.5 which it's predecessor included. The 2.6 that's included in SL also defaults to 64 bit. Although this is 'geeky' cool it has caused quite a few problems with other python applications/libraries. I'm sure this will change in the future but for now it's not so much fun.

A quick fix that quite a few people have done is doing either from the terminal
  defaults write Prefer-32-Bit -bool yes

With the first it's a permanent change, unless you re-execute it with 'no' in place of 'yes'.
The second is per session.

I didn't like the idea of making it permanent, and switching it all the time so I created a quick script.

#! bin/sh

python $PY_ARG

I also created the directory /usr/local/bin, as this isn't created in the default SL install but it is included in the default .bash_profile path variable so you don't have to update your path.

(I saved mine as
Then do a quick chmod to add the executable bits (sudo chmod 755 or sudo chmod u+x

Now I can simply type in '' and I've got Python 2.6 in 32-bits. Or if I wanted to run a python app/script in 32-bit I could type in ''

Happy scripting!!

No comments: