Recently, I was in a situation when it was needed to switch python versions for project test purposes. So I decided to write a blog post and describe a way of achieving this.
What about update-alternatives?
There is a solution (which is highly unrecommended to use) which may work if you want temporary switch python3 versions (for example python3.5 to python3.6):
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1Why this solution is bad? Because this may break soething in your system. For example, after doing this system updates stopped working for me until I switched python version back. So you should use this only for quick testing or not use at all.
Correct way: virtualenv
First of all, install virtualenv with pip if you haven't done
virtualenv allows to create isolated python environments.
It may also be useful if you want some application to use specific version of some package.
So you will need to create python environment for an app you are going to use specifying target python version:
virtualenv -p python3.6 ~/MY_APP_PATHYou may also add
--no-site-packagesif you want to isolate your application from global site-packages as well:
virtualenv -p python3.6 --no-site-packages ~/MY_APP_PATHThat's all setup required! You can create as many virtual environments as you need (for example you can create one for each of your applications).
To activate this virtual environment use:
source ~/MY_APP_PATH/bin/activateAnd to exit it later use:
That's it! It is simplier than you may expected!