解决_ssl.so: cannot open shared object file: No such file or directory
背景:
我在CentOS8.2的操作系统里安装完python2.7后,源码安装了OpenSSL_1_1_1-stable
下载地址:
https://github.com/openssl/openssl/tree/OpenSSL_1_1_1-stable
现象:
结果python导入ssl的时候报错了,报找不到_ssl.so这个库文件
>>> import ssl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/ssl.py", line 60, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: /usr/local/lib/python2.7/lib-dynload/_ssl.so: cannot open shared object file: No such file or directory
分析:
_ssl.so这个库文件找不到,是因为安装完OpenSSL_1_1_1-stable后,要再安装一次python,并且编译命令如:
./configure --with-ssl-default-suites=openssl --with-ensurepip=install
make altinstall
python 编译完成之后,才会在python2.7/lib-dynload 的目录下生成 _ssl.so 文件。这样再import就没问题了。
解决:
我不去手动编译了,全用yum 命令来吧。
yum install openssl-1:1.1.1k openssl-devel-1:1.1.1k libssl-dev
yum install python27
>>> import ssl # 成功了