ubuntu安装python3.10并设置默认

安装新版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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容