python2 and python3 installation configuration on Ubuntu

Ubuntu 20.04 LTS has removed Python2 and python3 is installed by default. However, the python2.7 version is often used in many cases. Here, first install python2.7 separately, and then configure python2 and python3 to manually switch the system default python version.

1.Install python2.7

Command: sudo apt install python2, press Enter all the way

2. Configure the system default python version

      Execute the following commands in sequence: set the priority of /usr/bin/python2.7 to 1, and set the priority of /usr/bin/python3.8 to 2. After executing the update-alternatives command, python3.8 is set to the system Default version

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1


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

3. View the current default version: enter python --version in the terminal

4. python instead of version information: terminal input sudo update-alternatives --list python

5. Manually switch the default version of python

Enter sudo update-alternatives --config python in the terminal

Enter 1 to set python2.7 as the default version, and enter 2 to set python3.8 as the default version.

Guess you like

Origin blog.csdn.net/qq_44848795/article/details/131277985