在Ubuntu 16.04(18.04) 系統上編譯安裝Python 3.8 方法
阿新 • • 發佈:2021-02-01
在Ubuntu 16.04(18.04) 系統上編譯安裝Python 3.8 方法
安裝編譯依賴
sudo apt install -y wget build-essential libreadline-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev
sudo apt update
下載解壓原始碼
sudo wget https://www.python.org/ftp/python/3.8.0/Python-3.8.6.tgz
tar xf Python-3.8.6.tgz
設定編譯引數
cd Python-3.8.6/
./configure --prefix=/usr/local/python3 --enable-optimizations
編譯及安裝
sudo make && sudo make install
如有需要 make 編譯完後可以將整個原始碼包打包
打包命令
tar cf py38make.tar Python-3.8.6 && gzip py38make.tar
到相同配置的機器上安裝,適用於雲端多臺相同的伺服器
sudo rm -rf Python-3.x.x # 刪除舊的原始碼資料夾
sudo rm -rf /usr/local/python3/ # 刪除舊二進位制檔案
解壓命令
tar xf py38make.tar.gz
cd Python-3.8.6
sudo make && sudo make install # 安裝3.8 版本
軟連線pip3 和python3.8,-f 強制建立有則覆蓋
sudo ln -sf /usr/local/python3/bin/python3.8 /usr/bin/python3.8
sudo ln -sf /usr/local/python3/bin/pip3 /usr/bin/pip3
測試pip 安裝軟體
pip list
可能出現報錯
File "/usr/local/lib/python3.8/subprocess.py", line 395, in check_output
**kwargs).stdout
File "/usr/local/lib/python3.8/subprocess.py", line 487, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '('lsb_release', '-a')' returned non-zero exit status 1.
注意:是/usr/local/lib/python3.8/路徑下缺少lsb_release.py檔案(具體報錯路徑檢視自己電腦報錯路徑),解決方法
sudo find / -name 'lsb_release.py'
# 注意檢視自己報錯路徑再複製
sudo cp /usr/lib/python3/dist-packages/lsb_release.py /usr/local/lib/python3.8/
pip list
升級pip
sudo pip install --upgrade pip