ubuntu16下升级python3的版本--升级到3.8
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
5.下一步,更新pip,如下
$ sudo apt install python3-pip
$ sudo pip3 install --upgrade pip
如果出现
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in
from pip import main
File "/usr/lib/python3/dist-packages/pip/init.py", line 14, in
from pip.utils import get_installed_distributions, get_prog
File "/usr/lib/python3/dist-packages/pip/utils/init.py", line 23, in
from pip.locations import (
File "/usr/lib/python3/dist-packages/pip/locations.py", line 9, in
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