ubuntu 18.04系统python3.6 升级到 python3.9

1.安装依赖库

sudo apt-get install build-essential libbz2-dev libssl-dev libreadline-dev libsqlite3-dev

2.下载 Python 3.9 源代码

wget https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tar.xz
# 解压
tar -xf Python-3.9.5.tar.xz

3.编译Python 3.9

cd Python-3.9.5
./configure
make

4.安装Python 3.9

sudo make install

5.更新Python链接

sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3.9 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.9 1

或者使用软链接:

sudo rm -rf /usr/bin/python
sudo rm -rf /usr/bin/python3

sudo ln -s /usr/local/bin/python3.9 /usr/bin/python
sudo ln -s /usr/local/bin/python3.9 /usr/bin/python3

然后自己验证一下安装的结果,在终端窗口输入python, python3 看版本信息输出是对的。

ubuntu 18.04系统python3.6 升级到 python3.9_第1张图片

你可能感兴趣的:(ubuntu,linux,python)