安裝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 <enter> 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)