Ubuntu – Any way to (easily) upgrade Python in Ubuntu

pythonUbuntu

I had Ubuntu 10.04 installed, which came with Python 2.6. Then I installed 3.1 and just used either one. At one point I think I installed a bunch of libraries as well, must've used apt-get to get a package of compiled libraries or something.

Either way, I updated to 10.10, which I think has Python2.7 as default. But if I run python in the console I still get the 2.6 shell. The problem I have is that I want to use ordered dictionaries, yet because I'm in 2.6 I can't. All the packages are installed in the 2.6 version, so I can only use 2.7 for trivial things. For example, 2.7 doesn't have PIL, numpy, opencv etc.

I tried removing the symbolic link from /usr/bin/python that was pointing to /usr/bin/python2.6 and adding a new one to /usr/bin/python2.7, and while it works, all my libraries are still in the old version. I then tried installing pip, but it didn't run. Returning /usr/bin/python to 2.6 however made pip work, which means it was installed for the 2.6 version despite my attempt to use it with 2.7.

Any suggestions that will help me upgrade without formatting or going bald?

Edit: this guy had a similar problem and no solution. 🙁

Best Answer

I think you need to set PYTHONPATH after changing the links. On a fresh install of Ubuntu 10.10 I just did, I have:

evadeflow(57)% echo $PYTHONPATH 
/home/evadeflow/lib/python2.6/site-packages:/usr/lib/python2.6/site-packages

You should set this in your environment so it points to the version you want to use (i.e., change the 2.6 to 2.7...)