Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Caezar

macrumors 6502
Original poster
Thread title says it all :D

I installed Python 3.1, but when I type python in the terminal, it launches python 2.5.1.

Can the two version coexist?
Can I uninstall 2.5.1?
If I can, should I?
 

iShater

macrumors 604
Aug 13, 2002
7,026
470
Chicagoland
Yes they can. Most likely each one went to a directory that has the version number in it's name.

Which one is in your PATH? that would be the one that gets launched.
 

GroovyLinuxGuy

macrumors regular
Apr 2, 2006
139
0
Canada
Thread title says it all :D

I installed Python 3.1, but when I type python in the terminal, it launches python 2.5.1.

Can the two version coexist?
Can I uninstall 2.5.1?
If I can, should I?
The PATH is an environment variable that is a list of directories that the operating system looks in to find commands issued by the user

You may have to look where python was installed and use the full path to that version
The default version on python is found at /usr/bin/python (actually that's just a symlink to /System/Library/Frameworks/Python.framework/Versions/2.5/bin/python)

Depending on how you installed it you might want to check /usr/bin or even easier do a
locate python | less
in the terminal and just look for where it was installed

You can then use
#!/usr/bin/python3.1 (or where ever your interpreter is located)
on your shebang line

Personally I create an /opt directory and install any newer versions there and just symlink it back to /usr/bin but that's just me :)

Cheers and I hope that made sense...still working on first morning coffees
 

Caezar

macrumors 6502
Original poster
Thanks.

Python 2.x is installed under /System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/

Python 3.x is installed under Macintosh HD/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/

Is there a way I can open the newer version from the terminal?
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
There are many ways. I would probably recommend (as the system probably likes 2.3 a lot) adding a symlink to /usr/local/bin called py3 or python3 or something like that like this:
sudo ln -s "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/python" /usr/local/bin/py3
The path to the 3.1 python executable might not be quite right, so you can just sub it in.

Then when you want to use version 3, you'd just type py3. When you wanted the 2.3, just type python. I would not change, at the system level, which one gets called by default. If you really, really want to get version 3 by typing python, you could add an entry to your bath by editing your .bash_profile, like:
export PATH=/my/new/dir:$PATH

Then you can make a symlink called python in /my/new/dir. That way, when you ran python from the terminal it would find the version 3 executable before it found the version 2 one. I think this would let the system still use the python it likes by name, but someone may need to correct me on this.

-Lee
 

Cinder6

macrumors 6502a
Jul 9, 2009
509
50
How did you install it? Did you download a package, or use MacPorts? Did you try typing 'python31'?
 

Cromulent

macrumors 604
Oct 2, 2006
6,802
1,096
The Land of Hope and Glory
A simple restart of the Terminal is often all that's needed to make path changes take effect - not a full log out and back in.

Normally you are right, but I have had instances were I have to do a full log out and back in again for changes to register. Normally that is when I am editing existing path entries rather than adding completely new ones though.
 

MikhailT

macrumors 601
Nov 12, 2007
4,582
1,325
Still no luck. I shut down my Mac, had a shower , brushed my teeth, went to bed, slept, woke up, turned my Mac back on, launched the terminal and went I type Python, it still launches 2.5.1.

How did I install: downloaded an image from www.python.org and opened the package.

Dude, just type python and press tab to see a list of all python binary files. it is most likely python3.1.

The default will always remain 2.5.1 unless you update your config to point to 3.1 instead.
 

Libripens

macrumors newbie
Jun 20, 2012
1
0
Just Type "python3"

I installed Python 3.2.3, and I was having the same problem. Finally, I typed "python3" in terminal and it worked. If just type "python" I get the previous version though.
 

MorphingDragon

macrumors 603
Mar 27, 2009
5,160
6
The World Inbetween
There are many ways. I would probably recommend (as the system probably likes 2.3 a lot) adding a symlink to /usr/local/bin called py3 or python3 or something like that like this:
sudo ln -s "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/python" /usr/local/bin/py3
The path to the 3.1 python executable might not be quite right, so you can just sub it in.

Then when you want to use version 3, you'd just type py3. When you wanted the 2.3, just type python. I would not change, at the system level, which one gets called by default. If you really, really want to get version 3 by typing python, you could add an entry to your bath by editing your .bash_profile, like:
export PATH=/my/new/dir:$PATH

Then you can make a symlink called python in /my/new/dir. That way, when you ran python from the terminal it would find the version 3 executable before it found the version 2 one. I think this would let the system still use the python it likes by name, but someone may need to correct me on this.

-Lee

Most linux distros use python3 as an alias, so if you're writing cross platform scripts/apps I would suggest python3.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.