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?
 
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.
 
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
 
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?
 
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
 
How did you install it? Did you download a package, or use MacPorts? Did you try typing 'python31'?
 
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.
 
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.
 
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.
 
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.
 
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.