1.部署环境
操作系统:CentOS release 6.10 (Final)
OpenSSL版本:OpenSSL 1.0.1e-fips 11 Feb 2013
https://www.cndba.cn/zhasir/article/3467
https://www.cndba.cn/zhasir/article/3467
下载获得的安装介质包如下:
Python-3.7.1.tgz
openssl-1.1.1a.tar.gz
3.Python安装
3.1.安装RPM
yum -y install zlib zlib-devel
yum -y install bzip2 bzip2-devel
yum -y install ncurses ncurses-devel
yum -y install readline readline-devel
yum -y install openssl openssl-devel
yum -y install openssl-static
yum -y install xz lzma xz-devel
yum -y install sqlite sqlite-devel
yum -y install gdbm gdbm-devel
yum -y install tk tk-devel
yum -y install libffi libffi-devel
3.2.升级OpenSSL
由于系统自带的OpenSSL版本过低,会导致pip命令后期无法正常使用,所以需要进行OpenSSL升级。由于官方推荐1.1.1版本,所以本次升级的便采用的是该版本。
1) 解压安装包https://www.cndba.cn/zhasir/article/3467
# tar -xvf openssl-1.1.1a.tar.gz
2) 编译源码,指定安装位置
# cd openssl-1.1.1a
# ./config --prefix=/usr/local/openssl
3) 安装
make && make install
4) 创建链接
# mv /usr/bin/openssl /usr/bin/openssl.old
# mv /usr/include/openssl /usr/include/openssl.old
# mv /usr/lib64/libssl.so /usr/lib64/libssl.so.old
# ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
# ln -s /usr/local/openssl/include/openssl /usr/include/openssl
# ln -s /usr/local/openssl/lib/libssl.so /usr/lib64/libssl.so
5) 建立动态链接
# echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
# ldconfig -v
6) 查看opensll版本
https://www.cndba.cn/zhasir/article/3467
# openssl version
OpenSSL 1.1.1a 20 Nov 2018
3.3.安装Python
1) 解压安装包
https://www.cndba.cn/zhasir/article/3467
# tar -xvf Python-3.7.1.tgz
2) 编译源码,指定安装位置
https://www.cndba.cn/zhasir/article/3467
https://www.cndba.cn/zhasir/article/3467
# cd Python-3.7.1
# ./configure --prefix=/usr/local/python3 --enable-shared CFLAGS=-fPIC --with-openssl=/usr/local/openssl
3) 安装
# make && make install
4) 配置环境变量https://www.cndba.cn/zhasir/article/3467https://www.cndba.cn/zhasir/article/3467
# vim /etc/profile
追加如下内容:
export PATH=$PATH:/usr/local/python3/bin
# source /etc/profile
5) 测试Python3
# python3
[GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
4.报错处理
4.1.pip3无法使用
错误信息:
/usr/local/python3/bin/python3.7: error while loading shared libraries: libpython3.7m.so.1.0: cannot open shared object file: No such file or directory
# find / -name libpython3.7m.so.1.0
/usr/local/python3/lib/libpython3.7m.so.1.0
# cd /etc/ld.so.conf.d
# vim python3.conf
添加如下内容如下:
/usr/local/python3/lib/
# ldconfig
测试pip3是否可以正常使用,列出内容则正常
# pip3 list
Package Version
---------- -------
pip 10.0.1
setuptools 39.0.1
版权声明:本文为博主原创文章,未经博主允许不得转载。
python linux openssl