CentOS/Ubuntu安装Python 3.9.10
环境预览
系统/程序 | 版本 |
---|
ubuntu | 18.04 |
python | 3.9.10 |
下载软件包并安装配置
安装软件依赖
CentOS
sudo yum install -y centos-release-scl 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
yum -y install devtoolset-8
scl enable devtoolset-8 bash
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 --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
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