Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

4 Answers 4

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.

share|improve this answer
    
+1 since I've been trying to figure this out all day. Indeed, on Snow Leopard, if setting the PATH in your shell configuration isn't working, editing /etc/path as you've suggested works perfectly. For me, the problem was getting both graphical and terminal emacs to recognize I wanted to use a custom python installation. Thanks for the tip! –  jrhorn424 Feb 22 '12 at 2:48

Maybe if you install Python via MacPorts, it'll upgrade the system version. I actually suspect not, as that seems sort of risky to me. But you may want to check out what MacPorts does when you install Python with it.

share|improve this answer

I've asked someone this question before and I was advised against changing the default version of python because parts of the operating may depend on the 2.7 version being where it is. That being said it's not that much more work to put the python3 command in your path. That's what I'm doing at the moment and it seems fine.

share|improve this answer

From my experience, using symlinks along with a properly ordered PATH is the way to have multiple versions of Python coexist in OS X or any other nix I can think of. OS X is just a little bit goofy, but it works the same way.

First get the full picture by running the following commands:

which python

Then:

ls -la /usr/bin/python*

and compare with:

ls -la /usr/local/bin/python*

See where the symlinks are pointing.

Based on the PATH you posted, since /usr/bin comes after /usr/local/bin and the others you are probably using the System python interpreter:

/usr/bin/python

If you installed python3.0 it will likely run as:

/usr/local/bin/python

Now that you know what is pointing where, and what interpreter is being loaded from the PATH, you can make the appropriate changes to the PATH and/or symlinks. You can then use the same techniques to confirm the proper changes.

For more good information about python installation on macOS see dive into python3 and farmdev.

share|improve this answer
    
/usr/local/bin/python doesn't exist but /usr/local/bin/python3 does. python3 --version gives my install (3.2). Can I simply rename that symlink to python so I don't have to type the 3? –  Steven Zezulak Jul 1 '11 at 4:01
    
If your PATH is ordered correctly (/usr/local/bin comes after /usr/bin), then you could just create a symlink that does that. –  Somantra Jul 1 '11 at 12:52
    
But if /usr/bin comes after /usr/local/bin then it will keep loading the system python (/usr/bin/python). –  Somantra Jul 1 '11 at 12:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.