CentOS/Ubuntu安装Python 3.9.10
环境预览
系统/程序 | 版本 |
---|---|
ubuntu | 18.04 |
python | 3.9.10 |
下载软件包并安装配置
安装软件依赖
CentOS
代码语言:javascript复制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
代码语言:javascript复制sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev
下载Python二进制包
代码语言:javascript复制wget https://www.python.org/ftp/python/3.9.10/Python-3.9.10.tgz
解压包
代码语言:javascript复制sudo tar -zxf Python-3.9.10.tgz
编译安装
代码语言:javascript复制cd Python-3.9.10/
# 检查依赖
#sudo ./configure --enable-optimizations
# 若是想指定安装目录可以
# 设置安装目录
sudo ./configure --prefix=/usr/lib/python3.9.10
sudo make
sudo make install
#
添加环境(如果没有指定安装目录,可以跳过此步骤)
代码语言:javascript复制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源
代码语言:javascript复制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