Okay so I haven’t written an article for quite a long time and here I am surprisingly posting something on switching python versions. Hell yeah I’m doing Python right now. In any case, there’s this program that I was tasked to modify. It is running on Python 2.6 but unfortunately the server to which it is going to be deployed is on Python 2.5. Don’t lecture on me about having the servers update its version because we don’t live in an ideal world and we live in a bureaucracy and there are some things that are not within our control.
So there, how would you be able to run two versions of Python in a single machine at the same time and being able to choose which one to use? I’ve googled an article on how to do this and here’s how you can do it:
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.6 1 sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.5 10 sudo update-alternatives --config python
After issuing the last command, you’ll see a neat option screen like this:
ridvan@ridvan-work:~$ sudo update-alternatives --config python There are 2 alternatives which provide `python'. Selection Alternative ----------------------------------------------- 1 /usr/bin/python2.6 *+ 2 /usr/bin/python2.5 Press enter to keep the default[*], or type selection number:
So if you want to test some applications if it runs on a specific version, this is definitely very helpful. 🙂