Ubuntu18.04 安装Python3.8 教程

1. 首先(安装相关依赖)


sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget

2. 更新pip


sudo apt-get install python3-pip

pip3 install --upgrade pip

pip3 -V

3. 下载源码


wget https://www.python.org/ftp/python/3.8.11/Python-3.8.11.tar.xz

4. 编译源码


./configure prefix=/usr/local/python3

sudo -s 
sudo make altinstall  //不要使用标准的make install,因为它将覆盖默认的系统python3二进制文件

5. 修改软连接

# 备份原先的软链接
sudo -s mv /usr/bin/python /usr/bin/python.bak
sudo -s mv /usr/bin/pip /usr/bin/pip.bk

# 设置新的软链接
ln -s /usr/local/python3/bin/python3.8 /usr/bin/python
ln -s /usr/local/python3/bin/pip3.8 /usr/bin/pip

6. 验证


python3.8 -V

pip3.8 -V

你可能感兴趣的:(Ubuntu18.04 安装Python3.8 教程)