Possible Duplicate:
Using Python on Mac

So, I see similar questions, but none of the answers work for me.

I updated Python to 3.1.3 from 2.6.1. Everything works, except: When I type python into Terminal, I get:

Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

So, how do I change the version of Python that runs in the Shell? I've tried the script that they provide. It adds their directory to my $PATH, but it still doesn't change the version that'd displayed from Terminal. Here's what I get when I echo $PATH:

/Library/Frameworks/Python.framework/Versions/3.1/bin:/Library/Frameworks/Python.framework/Versions/3.1/bin:/Library/Frameworks/Python.framework/Versions/3.1/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

It appears that the script provided has added their directory for every time I ran the script (I tried it a few times, naturally).

Here's some caps of what is in the other relevant folders it mentions:

/Library/Frameworks/Python.framework/Versions/3.1/bin

enter image description here

/usr/local/bin

enter image description here

/usr/bin

enter image description here

link|improve this question
feedback

closed as exact duplicate by Daniel Beck, Diago Jan 16 '11 at 15:11

This question covers exactly the same ground as earlier questions on this topic; its answers may be merged with another identical question. See the FAQ for guidance on how to improve it.

1 Answer

up vote 5 down vote accepted

Just type python3. You might need to change your $PATH by editing ~/.bash_profile:

PATH="/Library/Frameworks/Python.framework/Versions/3.1/bin:${PATH}"
export PATH

They did this for compatibility reasons, Python 3 breaks things.


You could define a shell function or alias to map python to python3, this way old scripts would continue to run, and you can type python and get version 3.

Add to .bash_profile:

alias python='python3'

/usr/bin/env python continues to provide Python 2.

link|improve this answer
When I type python3, I get -bash: python3: command not found. Ideas? – Nathan G. Jan 15 '11 at 21:55
@Nathan See my edited post. – Daniel Beck Jan 15 '11 at 22:01
Will that just add another link to the framework? I've got three or for already... – Nathan G. Jan 15 '11 at 22:03
@Nathan What do you mean by "link"? If the Python 3 bin directory is already on your path, python3 would have launched Python 3 instead of showing an error. The path simply defines which directories are searched for a program when you type its name. Since the python3 binary resides in the directory from my post, that directory needs to be added to the path. No file system changes or "links" added. – Daniel Beck Jan 15 '11 at 22:07
@Daniel Thanks for this. – iainlbc Jan 17 at 5:10
feedback

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