7

I have Python 2.7.3 and 3.2.3 installed on my Ubuntu 12.04 64bit (by default?). When I type "python", I want python 3.2 instead of 2.7.

Changing symlink "python" to link to python3 seems to cause big problems. Why is that and is there a way to do that?

lrwxrwxrwx 1 root root       7 Sep 28 19:15 python -> python2
lrwxrwxrwx 1 root root       9 Jun 18 13:26 python2 -> python2.7
-rwxr-xr-x 1 root root 2993592 Apr 10 02:46 python2.7
-rwxr-xr-x 1 root root    1652 Apr 10 02:46 python2.7-config
lrwxrwxrwx 1 root root      16 Jun 18 13:26 python2-config -> python2.7-config
lrwxrwxrwx 1 root root       9 Apr 10 17:12 python3 -> python3.2
lrwxrwxrwx 1 root root      11 Apr 10 02:13 python3.2 -> python3.2mu
-rwxr-xr-x 1 root root 2949952 Apr 10 02:13 python3.2mu
lrwxrwxrwx 1 root root      11 Apr 10 17:12 python3mu -> python3.2mu
lrwxrwxrwx 1 root root      16 Jun 18 13:26 python-config -> python2.7-config

I linked python to python3:

sudo ln -fs python3 python

It worked but later it forced me to change the link back because Ubuntu seems not much responsive and I can't run most of the applications any more, such as Variety, Spyder, Okular, Software Center, etc.

Edit:
Yes, the 2 answers in the marked duplicate question Problems upgrading to Python 3.3 and setting up Django addressed half of my question, and the question itself doesn't seem to be related to my question when I try to search for an answer. I doubt anyone would realize the answer is below that question.

1
  • 1
    As the answers say, instead trying to force your system to whenever you type python it uses python3 you either alias the python word, or just type the extra 3 at the end. You shouldn't mess with the system wide python since most of Ubuntu depends on python 2 to work. apt-cache rdepends python | nl list 4955 packages in my system. – Braiam Sep 29 '13 at 15:18
10

If you want to use python3 instead of python2.7 just when you manually run python applications, just add:

alias python='python3'

to your ~/.bash_aliases file. (The file may be empty depending on whether you have added any aliases in the past.)

The applications other than the ones you manually start will continue using python2.7 or python3 as before.

1
  • Thanks for the tip! It does exactly what I wanted without ruining the system. – hxin Sep 29 '13 at 6:41
4

It is not sloppiness or coincidence that there are two different versions of Python on your system.

A lot of the apps in Ubuntu and Ubuntu based distros work with Python 2.7. And there are also applications that work with Python 3.

Since Python 3 is not backwards compatible, by symlinking python to python3 you break a lot of dependencies, hence a lot of applications not working.

1
  • Thanks for the info. I didn't realize that Python is an essential part of the system. This is very different from Windows. – hxin Sep 29 '13 at 6:50

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