Macos – How to update the default Python installation/fix the $PATH on Mac OS X 10.6.7

macmacospathpython

I know this question has been asked before on this site, and I have found a couple worthy discussions, but the solutions I've found and tried do not work. I want to learn Python and I'm having trouble getting it set up properly on my Mac. I'm running OS X 10.6.7.

I've downloaded the Python 3.2 installer from python.org and installed it, which installed to /Library/Frameworks/Python.framework/Versions/3.2/bin. This is fine for now as I can simply use IDLE to develop. In order to use 3.2 from the command line using python I tried to reorder my $PATH variable. This is what ~/.profile looks like:

PATH=/Library/Frameworks/Python.framework/Versions/3.2/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin

However, python still launches 2.6.1:

steven-macbook:~ steven$ python --version
Python 2.6.1
steven-macbook:~ steven$ . ./.profile
steven-macbook:~ steven$ python --version
Python 2.6.1
steven-macbook:~ steven$ 

After struggling with that for a while, I decided I should simply uninstall 3.2 and try and update the system installation of Python. I'm unsure of how to properly do that, so I either need to get 3.2 working with the command line or update 2.6.1.

Best Answer

I just solved this problem by installing Python 3.2.2 on my Mac OS X Lion so I thought I would post how I did it in the hopes someone may find it helpful.

Firstly, I agree with shadesandcolour in that you should not modify the default copy of python that came with your mac because there could be scripts that may not work properly when run using the Python 3.0+ interpreter. Having said that, to install that latest Python (3.2.2 at the time of this post), you should first download the Python installer from the official website. Install as per normal. Run the "Update Shell Profile.command" file in /Applications/Python(ver) folder.

After python has been installed, you need to edit your path by typing "sudo nano /etc/paths" at the command line. Next, enter your password when prompted. Next just "cut" the line "/usr/local/bin" and "paste" it BEFORE the occurrence of "/usr/bin". Save the file, close any open terminals and run a new instance of terminal. Now when you type "python" at the command line, the shell will search through /usr/local/bin first and run the latest copy of python.