CentOS/Ubuntu编译安装Python 3.9.10《详细、无废话》

CentOS/Ubuntu安装Python 3.9.10

  • 环境预览
  • 下载软件包并安装配置
    • 安装软件依赖
      • `CentOS`
      • `Ubuntu`
    • 下载Python二进制包
    • 解压包
    • 编译安装
    • 添加环境(如果没有指定安装目录,可以跳过此步骤)
  • 修改pipy源

环境预览

系统/程序 版本
ubuntu 18.04
python 3.9.10

下载软件包并安装配置

安装软件依赖

CentOS

sudo yum install -y gcc patch libffi-devel python-devel  zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

Ubuntu

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

下载Python二进制包

wget https://www.python.org/ftp/python/3.9.10/Python-3.9.10.tgz

解压包

sudo tar -zxf Python-3.9.10.tgz

编译安装

cd Python-3.9.10/
# 检查依赖
sudo ./configure --enable-optimizations
# 若是想指定安装目录可以
# 设置安装目录
# sudo ./configure --prefix=/usr/lib/python3.9.10

sudo make

sudo make install
# 

添加环境(如果没有指定安装目录,可以跳过此步骤)

sudo echo "PATH=/usr/lib/python3.9.10/bin:\$PATH" >> /etc/profile
source /etc/profile

# 移除原有python3
mv /usr/bin/python3 /usr/bin/python3.bak
ln -s /usr/lib/python3.9.10/bin/python3 /usr/bin/python3

修改pipy源

pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple pip -U
pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simple

你可能感兴趣的:(Linux,Ubuntu,Python学习笔记,ubuntu,python,centos)