CentOS 7 Python3.9 编译安装
2020-12-27 本文已影响0人
炸鱼最好吃
准备依赖环境
yum -y install \
wget \
make \
gcc \
zlib* \
libffi-devel \
openssl-devel \
bzip2-devel \
ncurses-devel \
gdbm-devel \
sqlite-devel \
tk-devel \
readline-devel \
db4-devel \
libpcap-devel \
xz-devel
下载压缩包
wget https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz
编译安装
tar xvf Python-3.9.1.tgz
cd Python-3.9.1/
./configure --prefix=/usr/local/python
make -j 8
make altinstall
设置环境变量
cat <<eof|tee /etc/profile.d/python.sh
export PATH=\$PATH:/usr/local/python/bin
eof
source /etc/profile
ln -fs /usr/local/python/bin/python3.9 /usr/bin/python
yum设置python2.7
如果不设置,yum命令不可用。
sed -i '1d' /usr/bin/yum
sed -i '1i\#!/usr/bin/python2.7' /usr/bin/yum
sed -i '1d' /usr/libexec/urlgrabber-ext-down
sed -i '1i\#!/usr/bin/python2.7' /usr/libexec/urlgrabber-ext-down
升级pip
python -m pip install --upgrade pip
测试验证
有版本号输出说明安装成功。
python -V
pip --version