ubuntu16下升级python3的版本,这里是升级到3.8。
1.首先添加安装源,在命令行输入如下命令:
$ sudo add-apt-repository ppa:jonathonf/python-3.8
2.更新apt
$ sudo apt update
3.更新安装源后,通过apt安装Python3.8
$ sudo apt-get install python3.8
4.安装完成之后,设置Python3.8的优先级
$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 2
update-alternatives命令可以修改系统默认命令的软链指向,
参考这里,上面两句指令就是修改了系统默认的/usr/bin/python3 的软链指向,指向了两个位置,最后面的1和2是优先级
这时安装完成,可以通过python3 -V查看版本
5.下一步,更新pip,如下
$ sudo apt install python3-pip
$ sudo pip3 install --upgrade pip
如果出现
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 14, in <module>
from pip.utils import get_installed_distributions, get_prog
File "/usr/lib/python3/dist-packages/pip/utils/__init__.py", line 23, in <module>
from pip.locations import (
File "/usr/lib/python3/dist-packages/pip/locations.py", line 9, in <module>
from distutils import sysconfig
ImportError: cannot import name 'sysconfig' from 'distutils' (/usr/lib/python3.8/distutils/__init__.py)
解决方法:添加源
sudo vim /etc/apt/sources.list
添加以下
deb http://cn.archive.ubuntu.com/ubuntu/ bionic main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ bionic-proposed main restricted universe multiverse
保存退出后执行
sudo apt-get update
安装python3.8-distutils
sudo apt-get install python3.8-distutils
再重新执行安装pip
参考:
https://blog.csdn.net/mbdong/article/details/127662406
https://blog.csdn.net/qq_35505543/article/details/120345813
标签:sudo,apt,pip,usr,版本,ubuntu,ubuntu16,python3 From: https://www.cnblogs.com/hanzg/p/16950379.html