Ubuntu Python 3.6 updated to 3.8 and pip pit

Original link: http://i.lckiss.com/?p=8100

Background: I have written the Python finishing of the Mac environment before, and I have never tossed the Python environment of Ubuntu (or forgot), so let’s record it.

System: elementary OS 5.1.7 Hera (built on Ubuntu 18.04.6 LTS)

View the current version and related paths

Check the version used by the current system Python3:

 python3 -V

Check out the directory where these versions are located:

 python3 -c 'import sys;print(sys.path)'

If nothing else, there will be N versions, and for Ubuntu, don’t delete them, the general system will use Python2.7 (legacy of historical programs), and Python3.X (required by the current system), and we need to manually install a Python3. 8 or later.

Install

Due to the lag of the Ubuntu source, a third-party ppa is generally required:

 sudo apt install software-properties-common sudo add-apt-repository ppa:deadsnakes/ppa sudo apt update
 sudo apt install python3.8

Other methods include source code compilation. Software such as Python with a large number of installations generally does not need to be tossed by itself. After installation, check the Python version and you will find that it is still an old version.

version switch

Here we need to introduce a very magical package: update-alternatives. Of course, you can see by the name. It is a tool for switching between multiple software versions. Linux mainly relies on binary executable files to link to bin. In many cases, we manually relink and remove are both tedious and error-prone, which is where this tool comes in.

Create the relationship between the two versions (the –install corresponding parameter is the link location of the executable file and the associated chain name corresponds to the real execution path number of the binary file):

 sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 2

Then you can switch versions at will:

 sudo update-alternatives --config python3
 There are 2 candidates available to replace python3 (provided /usr/bin/python3).    Select Path Priority Status --------------------------------------------- --------------- * 0 /usr/bin/python3.8 2 Auto mode 1 /usr/bin/python3.6 1 Manual mode 2 /usr/bin/python3.8 2 Manual mode To maintain the current value[*] press <Enter >, or type the number of your choice:

I believe that it is easy to make a version selection. After selecting and viewing the version, it is the version you choose.

update pip

Only when the Python version is correct, the updated pip is the new version of the corresponding version. The command is simple:

 python -m pip install --upgrade pip

Or don’t worry about specifying the version:

 python3.8 -m pip install --upgrade pip

Do anything else~

above;

refer to:

https://phoenixnap.com/kb/how-to-install-python-3-ubuntu

This article is reproduced from: http://i.lckiss.com/?p=8100
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment