CentOS6编译安装Python3
原创
©著作权归作者所有:来自51CTO博客作者岳麓丹枫的原创作品,请联系作者获取转载授权,否则将追究法律责任
下载源代码
wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tar.xz
目录准备
mkdir -p /usr/local/python3.8.2
ln -s /usr/local/python3.8.2 /usr/local/python
解决pip is configured with locations that require TLS/SSL问题
安装依赖
yum install gcc libffi-devel zlib* openssl-devel
系统版本centos6.x,其中openssl的版本为OpenSSL 1.0.1e-fips 11 Feb 2013,而python3.7需要的openssl的版本为1.0.2或者1.1.x,需要对openssl进行升级,并重新编译python3。yum 安装的openssl 版本都比较低。
升级openssl
wget https://www.openssl.org/source/openssl-1.1.1a.tar.gz
tar -zxvf openssl-1.1.1a.tar.gz
cd openssl-1.1.1a
./config --prefix=/usr/local/openssl no-zlib #不需要zlib
make
make install
mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl/ /usr/include/openssl.bak
ln -s /usr/local/openssl/include/openssl /usr/include/openssl
ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/local/lib64/libssl.so
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
编译安装Python
./configure --prefix=/usr/local/python3.8.2 --with-openssl=/usr/local/openssl
make && make install
测试ssl模块成功
[root@localhost python3.8.2]# pip list
Package Version
---------------- ----------
appdirs 1.4.3
certifi 2019.11.28
distlib 0.3.0
filelock 3.0.12
pip 19.2.3
pipenv 2018.11.26
setuptools 41.2.0
six 1.14.0
virtualenv 20.0.7
virtualenv-clone 0.5.3
WARNING: You are using pip version 19.2.3, however version 20.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[root@localhost python3.8.2]# python
Python 3.8.2 (default, Mar 2 2020, 06:30:40)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>>