解决_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  # 成功了
相关推荐
万粉变现经纪人12 分钟前
如何解决 pip install 安装报错 ModuleNotFoundError: No module named ‘tokenizers’ 问题
python·selenium·测试工具·scrapy·beautifulsoup·fastapi·pip
编程武士2 小时前
从50ms到30ms:YOLOv10部署中图像预处理的性能优化实践
人工智能·python·yolo·性能优化
我的xiaodoujiao2 小时前
Windows系统Web UI自动化测试学习系列2--环境搭建--Python-PyCharm-Selenium
开发语言·python·测试工具
傻啦嘿哟5 小时前
Python SQLite模块:轻量级数据库的实战指南
数据库·python·sqlite
Q_Q5110082855 小时前
python+django/flask+uniapp基于微信小程序的瑜伽体验课预约系统
spring boot·python·django·flask·uni-app·node.js·php
XueminXu5 小时前
Python读取MongoDB的JSON字典和列表对象转为字符串
python·mongodb·json·pymongo·mongoclient·isinstance·json.dumps
techdashen5 小时前
12分钟讲解Python核心理念
开发语言·python
jie*5 小时前
小杰机器学习(nine)——支持向量机
人工智能·python·机器学习·支持向量机·回归·聚类·sklearn
闭着眼睛学算法5 小时前
【华为OD机考正在更新】2025年双机位A卷真题【完全原创题解 | 详细考点分类 | 不断更新题目 | 六种主流语言Py+Java+Cpp+C+Js+Go】
java·c语言·javascript·c++·python·算法·华为od
郝学胜-神的一滴5 小时前
谨慎地迭代函数所收到的参数 (Effective Python 第31条)
开发语言·python·程序人生·软件工程