安装pip3时,ubuntu默认安装python3.5的依赖,非最新版的3.7,而代码需要运行在python3.7,可如下操作:
1、安装python3.7
#apt-get install software-properties-common
#add-apt-repository ppa:deadsnakes/ppa
#apt-get update
#apt-get install python3.7
#python3.7
Python 3.7.4 (default, Sep 2 2019, 20:44:09)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
2、修改一下优先级,让输入python3时出来的就是python3.7
#sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1
#sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
#update-alternatives --config python3
There are 2 choices for the alternative python3 (providing /usr/bin/python3).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/python3.7 2 auto mode
1 /usr/bin/python3.5 1 manual mode
* 2 /usr/bin/python3.7 2 manual mode
Press to keep the current choice[*], or type selection number: 2
#python3
Python 3.7.4 (default, Sep 2 2019, 20:44:09)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
3、安装或升级pip3
#安装
#apt-get install python3-pip
#升级
#sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall
#pip3 --version
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.7)