centos7安装python3
1.准备安装工具
yum groupinstall "Development tools"
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-develtk-devel gdbm-devel db4-devel libpcap-devel xz-devel
2.下载python3源码
wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz
3.解压
tar xf Python-3.7.5.tgz ./
4.进入下载目录
cd Python-3.7.5
5.编译
./configure --prefix=/usr/local/python3
make&& make install
6.创建软链接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
7. 问题处理
解决pythonssl问题
因openssl 1.0.1存在安全问题,python3自3.7版本后要求依赖openssl 1.0.2以上或libressl;错误提示如下:
Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_P
python3.7以上建议使用libressl代替openssl,故需通过源码编译安装libressl
下载源码包
wget https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-3.0.2.tar.gz
解压
tar -zxvf libressl-3.0.2.tar.gz
配置安装路径
mkdir /usr/local/libressl
cd libressl-3.0.2
./configure --prefix=/usr/local/libressl
安装
make & make install
创建软连接代替openssl
mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl /usr/include/openssl.bak
ln -s /usr/local/libressl/bin/openssl /usr/bin/openssl
ln -s /usr/local/libressl/include/openssl /usr/include/openssl
echo /usr/local/libressl/lib >> /etc/ld.so.conf.d/libressl-3.0.2.conf
ldconfig -v
验证是否安装完成
openssl version
export LDFLAGS="-L/usr/local/libressl/lib"
export CPPFLAGS="-I/usr/local/libressl/include"
export PKG_CONFIG_PATH="/usr/local/libressl/lib/pkgconfig"
配置编译安装python
./configure --prefix=/usr/local/python3
make
make install