Python3中无法导入ssl模块的解决办法和python3.7 ModuleNotFoundError: No module named bz2解决办法
一、Python3中无法导入ssl模块的解决办法
1.安装完python3,在运行python文件时提示找不到ssl模块。
[root@yz]# python
>>> import ssl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/python37/lib/python3.7/ssl.py", line 60, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: No module named _ssl
>>>
2.查看openssl安装包,命令如下:
rpm -aq|grep openssl
发现缺少openssl-devel包
3.安装openssl-devel包命令:
yum install openssl-devel -y
再次使用命令查看:rpm -aq|grep openssl,发现已经不再缺少。
4.重新编译python
进入到python的解压目录,#修改Setup文件
vi ..../Python-3.7.0/Modules/Setup
#修改结果如下:
# 通过输入:?ssl 快速查找到定位到以下内容
# Socket module helper for socket(2)
_socket socketmodule.c timemodule.c #去除该行注释(备注)
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
_ssl _ssl.c \ #去除该行注释(备注)
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \ #去除该行注释(备注)
-L$(SSL)/lib -lssl -lcrypto #去除该行注释(备注)
5.重新编译安装python.
6.终端输入python,再输入import ssl不报错,测试成功
二、python3.7 ModuleNotFoundError: No module named bz2解决办法
1.终端输入如下命令
yum install zlib zlib-devel
yum -y install bzip2 bzip2-devel ncurses openssl openssl-devel openssl-static xz lzma xz-devel sqlite sqlite-devel gdbm gdbm-devel tk tk-devel libffi-devel
2.在python安装目录输入make distclean,然后重新编译安装python.
本文地址:https://blog.csdn.net/sinat_36831355/article/details/107325982
上一篇: 处暑吃啥好?处暑节气的含义是什么?