Ubuntu downloads and switches the default version of Python (painless and smooth version)

How to download and switch the default version of Python on Ubuntu

I. Introduction

When preparing for the completion of the sophomore project, to install the mediapipe library, you need to download and switch the python version in ubantu to 3.8. I encountered some minor problems, and I will record them by the way.
Note: The following steps will not pollute the environment, please rest assured to eat.

Second, download the specified python version in ubantu

Here I take python3.9 as an example.

1. Update the apt version to the latest

sudo apt update

2. Install software-properties-common

sudo apt install software-properties-common

software-properties-common provides an abstraction of the apt repositories used. It allows you to easily manage distribution and independent software vendor software sources.

3. Add the deadsnakes PPA to your system source list

sudo add-apt-repository ppa:deadsnakes/ppa


Press [ENTER] to continue or Ctrl-c to cancel adding it when prompted .

4. Install python3.9

 sudo apt install python3.9

5. Verify whether the installation of 3.9 is successful

python3.9 -V

insert image description here
If so, the installation was successful.

3. Soft link python to 3.9

After the download is successful, we enter python3 -V and find that the version of python3 has not been modified. At this time, only the last step is left. Set the python3 soft connection to python3.9 . The following are the specific steps

1. Check which python versions are currently downloaded

 ls /usr/bin/python*

insert image description here
The picture above is my display. You can see that I have four python versions, 2.7, 3.6, 3.8, and 3.9.

2. Use alternatives to change the Python version of the entire system

Before the change:
insert image description here
the specific steps to change to 3.9 are as follows:

a. Set the soft link sequence of python3

Set the python soft link python3.6 priority to 1, soft link python3.9 priority to 2, the following is the code

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

Note: sudo update-alternatives --remove python /usr/bin/python3.9, enter this to delete the link

b. Check whether the link sequence is set successfully

sudo update-alternatives --display python

insert image description here
A similar display means that the setting is successful

c. Modify and view the python version of the python link

sudo update-alternatives --config python

insert image description here
At the beginning, it is number 2, which is python3.6. I input 4 to select the link python3.9. You can enter the selection number according to your own situation.

python -V

insert image description here
As you can see, the python version link has changed to
py3.9

Guess you like

Origin blog.csdn.net/qq_51116518/article/details/130184514