安装依赖
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
下载以及解压
wget https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tar.xz
tar -xvJf Python-3.7.6.tar.xz
编译安装
mkdir /usr/local/python3 #创建编译安装目录
cd Python-3.7.6
./configure --prefix=/usr/local/python3
make && make install
创建软链接
ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3
验证
python3 --version
pip3 -V
补充:
python 支持ssl 先尝试使用openssl-1.1.1c安装后失败。
使用libressl替代
下载
https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-2.8.0.tar.gz
./configure --prefix=/usr/local/ssllib
(如果/usr/local下有ssl 以及include/openssl 可以删掉 把ssllib下安装好的ssl 以及include/openssl 复制到对应的目录下)
进入Python安装目录
修改Modules/Setup Modules/Setup.dist 取消这几行的注释,并修改SSL=/usr/local/ssl 为SSL=/usr/local
# Socket module helper for socket(2)
_socket socketmodule.c
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=/usr/local
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
重新编译Python
./configure --prefix=/usr/local/python3
make 验证一下有没有错
make install