解决_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这个库文件

python 复制代码
>>> 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,并且编译命令如:

python 复制代码
./configure --with-ssl-default-suites=openssl --with-ensurepip=install
make altinstall

python 编译完成之后,才会在python2.7/lib-dynload 的目录下生成 _ssl.so 文件。这样再import就没问题了。

解决:

我不去手动编译了,全用yum 命令来吧。

python 复制代码
yum install openssl-1:1.1.1k openssl-devel-1:1.1.1k libssl-dev
yum install python27

>>> import ssl  # 成功了
相关推荐
烤汉堡9 小时前
Python入门到实战:post请求+cookie+代理
爬虫·python
luod9 小时前
Python异常链
python
我不是QI10 小时前
周志华《机器学习---西瓜书》 一
人工智能·python·机器学习·ai
今天没ID10 小时前
Python 编程实战:从基础语法到算法实现 (1)
python
二川bro10 小时前
Python在AI领域应用全景:2025趋势与案例
开发语言·人工智能·python
棒棒的皮皮11 小时前
【Python】Open3d用于3D测高项目
python·3d·open3d
CodeLongBear11 小时前
Python数据分析: 数据可视化入门:Matplotlib基础操作与多坐标系实战
python·信息可视化·数据分析
李晨卓11 小时前
python学习之不同储存方式的操作方法
python·代码规范
站大爷IP11 小时前
实战:爬取某联招聘职位需求并生成词云——从零开始的完整指南
python
deephub11 小时前
从零开始:用Python和Gemini 3四步搭建你自己的AI Agent
人工智能·python·大语言模型·agent