5

Possible Duplicate:
How do I make the terminal run python 3.1?

I am using Ubuntu 10.10 and just installed Python 3.1 but entering python on my Gnome Terminal gets me Python 2.6 . How to fix it to get Python 3.1 on typing python on the terminal ?

explorest
  • 153

2 Answers2

7

I can't sanction Dayjay's answer at all. Replacing Python system-wide could make applications hugely unstable and in a lot of cases, they'll just break.

  • Python-based libraries are installed to a version-specific place (eg /usr/lib/python2.6/) so swapping in a new version without catering for existing packages will break things that need things on the right Python path.

  • There are major language differences between 2.6 and 3.x that, if a package doesn't check to see what version it's using (common of older scripts) could make things unstable.

    For example, if you divide two ints in 2.6 you are returned a floored int; but in 3.x it'll return a float.

The safest thing to do is just call the 3.x binary when you want to use Python 3.x.

python3.1 my_python_script.py
Oli
  • 293,335
  • You are right , but his answer is probably ok for my specific scenario which is a lot less critical then you might suspect. I have just installed a Ubuntu guest OS on a virtual box (hosted by Windows 7 ) at my home PC. The whole point is to play around with the distro including the use of Gnome terminal and Python 3 in Linux. It does not matter even if the whole system is screwed... its used as a toy anyway. I did use the python3.1 command on the shell , and it worked well ... but was a little inconvenient. So I wanted to just use the python command for the 3.1 version. – explorest Apr 07 '11 at 12:34
  • By the way, if it were a critical situation, then what would you suggest to reverse what I did by changing the symlink. Simply execute the inverse commands and restore the symlink to Python 2.6 ? – explorest Apr 07 '11 at 12:36
  • Yeah, just delete the symlink again and make a new one back to /usr/bin/python2.6 – Oli Apr 07 '11 at 12:58
  • One funny thing (probably a major system screw up) that I noticed after the original redirection of the link to Python 3.1 was that the Ubuntu Software Center wont start on clicking..... it just wont , even after reinstalling the Ubuntu Softwar Center. Now when I reversed the default version to Python 2.6 ... it started to work again ... lolz ... yeah that was fun !! – explorest Apr 07 '11 at 19:59
-2

You could simply change the symlink:

rm /usr/bin/python
ln -s /usr/bin/python3.1 /usr/bin/python
Dayjay
  • 526
  • I don't know why this answer is getting downvoted. He wanted to run python 3.1 if he types python (for any reasons), thats exactly what it does. – Dayjay Apr 08 '11 at 06:09
  • I wouldn't say that changing the symlink is a security concern, but editing system files (including symlinks to system files) without understanding exactly what they do and why they do it that way can expose a user to a lot of problems that they might not be able to solve. –  Apr 10 '11 at 02:39