安装新版python:
sudo apt update && sudo apt upgrade -y
sudo apt install software-properties-common -y
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.10
验证版本
python3.10 --version
## 设置Python3.10 默认
$ python3 --version
Python 3.6.9
$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
update-alternatives: using /usr/bin/python3.6 to provide /usr/bin/python3 (python3) in auto mode
python3.10 --version
Python 3.10.4
$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 2
update-alternatives: using /usr/bin/python3.10 to provide /usr/bin/python3 (python3) in auto mode
$ sudo update-alternatives --config python3
There are 2 choices for the alternative python3 (providing /usr/bin/python3).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python3.10 2 auto mode
1 /usr/bin/python3.10 2 manual mode
2 /usr/bin/python3.6 1 manual mode
Press <enter> to keep the current choice[*], or type selection number: 1
安装pip3
python3.10版本pip3貌似有问题,我降到3.9了。
出现问题:
ImportError: cannot import name 'sysconfig' from 'distutils' (/usr/lib/python3.9/distutils/__init__.py)
sudo apt install python3.9-distutils
sudo add-apt-repository
添加仓库出现错误:
ModuleNotFoundError: No module named 'apt_pkg'
修改:
/usr/bin/add-apt-repository 中文件头指向原始python版本
如:#!/usr/bin/python3.6
网友评论