Linux离线安装Python时ssh和hashlib死活安装不上的解决方案

        背景:此次Linux服务器为虚拟机,没有连接网络,手动安装了openssl-1.0.2p,openssh-7.1p2,使得ssh -V的openssl版本和openssl version版本保持一致。想要如何安装升级openssl和openssh,请在我的Linux栏目里查看相关文章。然后源码安装python2.7.13,make编译的时候出现_ssh和_hashlib这两个模块死活装不上,即“ImportError: No module named _ssl”和“ERROR:root:code for hash md5|sha1|sha224|sha256|sha384|sha512 was not found”,共两个问题。最后看到某一大神的文章:http://blog.sina.com.cn/s/blog_3c8ced580100zxq9.html,才得以解决。

问题1:“ImportError: No module named _ssl”的解决方案如下:

#编辑配置文件

vi /etc/profile

#新增OpenSSL环境变量

export LDFLAGS='-L/usr/local/openssl/lib'
export CPPFLAGS='-I/usr/local/openssl/include'
export PKG_CONFIG_PATH='/usr/local/openssl/lib/pkgconfig'

#刷新配置文件

source /etc/profile

#编辑配置文件

vi Modules/Setup

#解除注释

218 SSL=/usr/local/openssl
219 _ssl _ssl.c \
220     -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
221     -L$(SSL)/lib -lssl -lcrypto

#编辑配置文件

vi Modules/Setup.dist

#解除注释

218 SSL=/usr/local/openssl
219 _ssl _ssl.c \
220     -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
221     -L$(SSL)/lib -lssl -lcrypto

然后问题1就解决了。

问题2:“ERROR:root:code for hash md5|sha1|sha224|sha256|sha384|sha512 was not found”的解决方案如下:

#编辑配置文件

vi Modules/Setup

#解除注释

255 _md5 md5module.c md5.c
256
257
258 # The _sha module implements the SHA checksum algorithms.
259 # (NIST's Secure Hash Algorithms.)
260 _sha shamodule.c
261 _sha256 sha256module.c
262 _sha512 sha512module.c

#编辑配置文件

vi Modules/Setup.dist

#解除注释

255 _md5 md5module.c md5.c
256
257
258 # The _sha module implements the SHA checksum algorithms.
259 # (NIST's Secure Hash Algorithms.)
260 _sha shamodule.c
261 _sha256 sha256module.c
262 _sha512 sha512module.c

然后问题2就解决了。

此时进入Python的解压目录,可以依次执行如下命令:

#进入目录

cd Python-2.7.13

#清空编译

make clean

#选择安装目录

./configure --prefix=/usr/local/Python-2.7.13 --with-ssl

#编译

make

#安装

make install

#Python安装完成后,在python环境下验证是否可以导入ssl模块,无报错即成功。

import ssl
import hashlib


 

猜你喜欢

转载自blog.csdn.net/Cai181191/article/details/120647308