欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 培训 > ubuntu20.04默认的python3.8升级到python3.10

ubuntu20.04默认的python3.8升级到python3.10

2025/10/21 13:32:59 来源:https://blog.csdn.net/lilongsy/article/details/143800357  浏览:    关键词:ubuntu20.04默认的python3.8升级到python3.10

Python 3.8 于 2019 年 10 月发布,距今已有五年时间。2024 年 10 月是 Python 3.8 版本发布的最后一个月,从 2024 年 10 月开始,如果存在安全错误,Python 开发团队将不会修复该错误。有必要把python3.8升级python3.10。

新加apt源

$ sudo apt install software-properties-common
$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt-get update
Hit:1 http://mirrors.aliyun.com/ubuntu focal InRelease
Hit:2 http://mirrors.aliyun.com/ubuntu focal-updates InRelease
Hit:3 http://mirrors.aliyun.com/ubuntu focal-backports InRelease
Hit:4 http://mirrors.aliyun.com/ubuntu focal-security InRelease            
Hit:5 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal InRelease       
Reading package lists... Done

安装python3.10

$ sudo apt-get install python3.10
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:libpython3.10-minimal libpython3.10-stdlib python3.10-minimal
Suggested packages:python3.10-venv binfmt-support
The following NEW packages will be installed:libpython3.10-minimal libpython3.10-stdlib python3.10 python3.10-minimal
0 upgraded, 4 newly installed, 0 to remove and 117 not upgraded.
Need to get 5,221 kB of archives.
After this operation, 20.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main amd64 libpython3.10-minimal amd64 3.10.15-1+focal1 [825 kB]
Get:2 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main amd64 python3.10-minimal amd64 3.10.15-1+focal1 [2,077 kB]                                                                                                                      
Get:3 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main amd64 libpython3.10-stdlib amd64 3.10.15-1+focal1 [1,763 kB]                                                                                                                    
Get:4 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main amd64 python3.10 amd64 3.10.15-1+focal1 [556 kB]                                                                                                                                
Fetched 5,221 kB in 7min 59s (10.9 kB/s)

设置默认版本为 Python3.10

查看系统已有python版本

$ ls -l /usr/bin/python*
lrwxrwxrwx 1 root root       9 Mar 13  2020 /usr/bin/python3 -> python3.8
-rwxr-xr-x 1 root root 5801848 Sep  7 18:35 /usr/bin/python3.10
-rwxr-xr-x 1 root root 5478168 Sep 11 16:02 /usr/bin/python3.8
lrwxrwxrwx 1 root root      33 Sep 11 16:02 /usr/bin/python3.8-config -> x86_64-linux-gnu-python3.8-config
lrwxrwxrwx 1 root root      16 Mar 13  2020 /usr/bin/python3-config -> python3.8-config

1

设置Python3默认版本

将python3.8优先级设置为1

$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
update-alternatives: using /usr/bin/python3.8 to provide /usr/bin/python3 (python3) in auto mode

将python3.10设置为默认版本,优先级设置为2

$ 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

选择默认版本 python3.10

$ 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 mode1            /usr/bin/python3.10   2         manual mode2            /usr/bin/python3.8    1         manual modePress <enter> to keep the current choice[*], or type selection number: 0

1

修复pip

$ sudo apt install python3.10-distutils
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$ python3 get-pip.py

权限问题

$ python3 get-pip.py --user

检查是否安装成功

python3 --version
Python 3.10.15

相关链接

https://blog.csdn.net/m0_46669450/article/details/140791499

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词