#ubuntu16.04升級python3.7.1教程 準備 sudo apt-get install --reinstall zlibc zlib1g zlib1g-dev sudo apt-get install libffi-dev libssl-dev libreadline-dev -y ...
ubuntu16.04升級python3.7.1教程
-
準備
sudo apt-get install --reinstall zlibc zlib1g zlib1g-dev sudo apt-get install libffi-dev libssl-dev libreadline-dev -y
-
安裝
使用python官方站點的以下命令下載Python。您也可以下載最新版本代替下麵指定的版本
#下載python3.7.1 sudo wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz #解壓 sudo tar xzf Python-3.7.1.tgz
-
進入解壓目錄
cd Python-3.7.1/
-
4、建立安裝的目錄
sudo mkdir -p /usr/local/python3
-
編譯安裝
#執行這步是後面最好加上 --enable-optimizations 會自動安裝pip3及優化配置 #./configure:配置安裝環境 #--prefix=/usr/local/python3:指向安裝路徑 #--enable-optimizations:安裝pip3及優化配置 ./configure --prefix=/usr/local/python3 --enable-optimizations make sudo make install
-
刪除軟連接
> #先執行查看版本,如果有則證明軟鏈接已存在,需要先刪去以前的再重新建立 > #這裡表明我已有python3的軟鏈接而沒有pip3的軟鏈接所以需要刪除python3的軟鏈接重新建立 > jianjiacheng@J-computer:~/Python-3.7.1$ python3 -V > Python 3.5.2 > jianjiacheng@J-computer:~$ pip3 -V > bash: /usr/lib/command-not-found:/usr/bin/python3: bad interpreter: No such file or directory > apt install python3-pip > rm -rf /usr/bin/python3 > rm -rf /usr/bin/pip3
-
建立新的指向python3.7的軟鏈接
添加python3的軟鏈接
ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3
添加 pip3 的軟鏈接
ln -s /usr/local/python3/bin/pip3.7 /usr/bin/pip3
-
檢測版本
jianjiacheng@J-computer:~$ python3 -V
Python 3.7.1jianjiacheng@J-computer:~$ pip3 -V
pip 10.0.1 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7) -
複製‘lsb_release.py’模塊
將其複製到設置python3.7的系統模塊載入位置,也就是報錯處subprocess.py所在的目錄
sudo cp /usr/lib/python3/dist-packages/lsb_release.py /usr/local/python3/lib/python3.7/
-
缺少‘lsb_release.py’模塊:
[【問題解決】subprocess.CalledProcessError: Command ‘(‘lsb_release‘, ‘-a‘)‘ returned non-zero exit status 1][1]
[1]: https://blog.csdn.net/p1279030826/article/details/111573774