Multiple versions of Python on Mac with Macports

Python on Mac!Linux users would be familiar with “aptitude” as our virtual swiss army knife to install useful open source packages and software.

The bash command:

sudo aptitude install [package name]

gets us what we want most of the time.  Some less-common software library requires more tweaking and our manual intervention to make and build of course, but in general “aptitude” suffices.


On Mac OS, “port” is our new best friend.  You can find out all about the MacPorts project over on

sudo port install [package name]

does most of our heavy lifting whenever we need to install 3rd party, open source libraries.

After we have downloaded the appropriate dmg file and installed the appropriate version (it has different versions for Snow Leopard, Leopard and Tiger), we should make sure that we have the latest available release by running:

sudo port -v selfupdate


My Mac Snow Leopard comes pre-installed with the the Apple Darwin‘s version of Python 2.6.1, which is a little outdated for my taste.

Since I already have MacPorts installed, I can now get up-to-speed with the latest version of Python by running:

sudo port install python26
sudo port install python27
sudo port install python_select
sudo python_select python26

To view the list of different Python versions available on my Mac, I can simply type:

python_select -l

Because I have also installed Python 3.1 to check out the coolest features in Python 3 while I still work with a lot of legacy projects running Python 2.6, here are the results from my terminal when I run “python_select -l”:

calvin$ python_select -l
Available versions:
current none python24 python25 python26 python26-apple python27 python31


Since I can’t stand working with the plain Python shell, my modus operandi would be also to install iPython for Python 2.6, like this:

sudo port -v install py26-ipython

The command for running this iPython shell will be located in /opt/local/bin/ipython2-6.

UPDATES: Useful Commands

So a friend who’s new to Python and learning all about Python and Django emailed me to ask me some questions.  In response, I have listed out some commands which I think would be useful to him.

which python       # Shows us the path to our Python program
python --version  # Tells us which version of Python we are currently using
python_select -l   # Lists out the different versions of Python we have in our OS
sudo python_select python26      # Selects Python 2.6 for current use!

If you have any other interesting and useful commands to share, pray tell.