The solution to switch Python3 version in Ubuntu installation configuration

sudo apt update

sudo apt install software-properties-common

sudo add-apt-repository ppa:deadsnakes/ppa

sudo apt install python3.9

python3.9 --version

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

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

sudo update-alternatives --config python3

python3 --version

 

image

image

image

 

ModuleNotFoundError: No module named'apt_pkg' problem solution

cd /usr/lib/python3/dist-packages/

sudo ln -s apt_pkg.cpython-36m-x86_64-linux-gnu.so apt_pkg.so

If it is reported that apt_pkg.so already exists, use the command

sudo ln -fs apt_pkg.cpython-36m-x86_64-linux-gnu.so apt_pkg.so

Mandatory add

 

Reference link

https://www.itsupportwale.com/blog/how-to-upgrade-to-python-3-7-on-ubuntu-18-10/ 

image

image

 

 

Install each version of Python3 and switch the Python version according to actual needs

sudo apt install python3.6

sudo apt install python3.7

sudo apt install python3.8

sudo apt install python3.9

 

sudo update-alternatives --config python3

python3 --version 

image

 

ImportError: cannot import name'sysconfig' problem solution

pip3

sudo apt-get remove python3-pip

sudo vim /etc/apt/sources.list

 

Add the following source

deb http://cn.archive.ubuntu.com/ubuntu bionic main multiverse restricted universe

deb http://cn.archive.ubuntu.com/ubuntu bionic-updates main multiverse restricted universe

deb http://cn.archive.ubuntu.com/ubuntu bionic-security main multiverse restricted universe

deb http://cn.archive.ubuntu.com/ubuntu bionic-proposed main multiverse restricted universe 

image

image

 

 

sudo apt-get update

sudo apt upgrade

sudo apt-get install python3-pip

sudo apt-get install python3-distutils

sudo update-alternatives --config python3

python3 --version 

image

image

 

 

If you want the default python version to be python3 instead of python 2.x, please refer to this tutorial

https://www.jianshu.com/p/48b1675495e8

 

image

Welcome everyone to follow the WeChat public account

Guess you like

Origin blog.csdn.net/u011426115/article/details/113032808