There are many of versions of Python, the different versions have different functions. But the more important thing is, some useful packages are worked on the specific versions.
Today I want to note how to install different python versions and switch them in our Linux system.
Download and Installation
First we must to confirm the python version we need, and we can use the following url to check all the version python have: https://www.python.org/ftp/python/
For example, I want to download the python 3.6.9:
wget https://www.python.org/ftp/python/3.6.9/Python-3.6.9.tgz
tar -zxvf Python-3.6.9.tgz
cd Python-3.6.9
The I make
it:
./configure --with-ssl --prefix=/usr/local/python3
make
sudo make install
How to Switch Python Version
After installation, we need to delete the old symbol link of python, and point to the new version path we installed (Both python and pip).
sudo rm /usr/bin/python3
sudo rm /usr/bin/pip3
sudo ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3
sudo ln -s /usr/local/python3/bin/pip3.6 /usr/bin/pip3
After switching, remember to use -V
or -version
argument to check the current python version:
python3 -V
pip3 -V
Output:
Python 3.6.9
pip 18.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
References
- https://linuxconfig.org/how-to-change-from-default-to-alternative-python-version-on-debian-linux
- https://medium.com/coderlist/how-to-change-default-python-version-on-linux-fedora-28-c22da18bdd6
- https://unix.stackexchange.com/questions/410579/change-the-python3-default-version-in-ubuntu/410851
- https://stackoverflow.com/questions/19256127/two-versions-of-python-on-linux-how-to-make-2-7-the-default