【发布时间】:2021-02-12 18:52:26
【问题描述】:
在我的 python 脚本中,我使用 requests 模块调用 API 来获取和发布数据。
Python 环境:anaconda3、python 3.7 / 包:requests 2.24.0、pyinstaller 3.6、openssl 1.1.1h...
PyInstaller 生成的 EXE 文件存在以下问题:运行此文件时,我收到以下错误消息。当我从 Python 运行我的脚本时,不会发生此错误:
Traceback (most recent call last):
File "site-packages\PyInstaller\loader\rthooks\pyi_rth_certifi.py", line 13, in <module>
File "c:\programdata\anaconda3\envs\...\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
File "ssl.py", line 98, in <module>
ImportError: DLL load failed: The specified module could not be found.
[20188] Failed to execute script pyi_rth_certifi
如果我遵循例外错误行 (ssl.py):
import _ssl # if we can't import it, let the error propagate
为什么不能导入ssl?
我在 SO 上的几篇帖子中搜索了很长时间,但所有这些答案都没有帮助,例如:
Python Requests throwing SSLError
Python Requests - How to use system ca-certificates (debian/ubuntu)?
Twilio Python Module Errors After Compiling
Fixing SSL certificate error in exe compiled with py2exe (or PyInstaller)
有人知道如何解决这个问题吗? 如果您需要更多信息,请写评论。谢了
编辑:(对于 Mooncrater 的评论)
从 python 控制台添加截图,输入:
import _ssl
编辑 2:
从 SO Question 测试了“FIX”: Python SSL Import Error in PyInstaller generated executable
->这并没有解决我的问题
编辑 3:cbolwerk 回答
感谢您的回答,这行得通!
Python 3.7 anaconda environment - import _ssl DLL load fail error
另一个解决方法是安装最新的 OpenSSL Lib,我在我的 python 脚本中使用了 1.1.1h 包,在我的 PC 上安装了旧版本,这也会导致错误。
cbolwerk 的答案我在没有安装 OpenSSL 的 PC 上测试过,正如我所写,它可以工作!
【问题讨论】:
-
@Mooncrater 我尝试了一个旧的python版本,同样的问题!
-
@droebi 您能否在创建 EXE 时尝试在 Python 3.6.8 中添加
--hidden-import pyodbc?取自this 答案。我之前也遇到过类似的问题。 -
@Mooncrater 我试过这个修复,同样的问题 :( ...但是非常感谢你到目前为止的支持
-
嗯,这很奇怪。我认为,特别是出于这个原因,我坚持使用 Python 3.6.8 + Pyinstaller 组合。也许您也应该在 pyinstaller 的 repo 页面上提出问题。这可能会导致一些事情。
-
@Mooncrater 是的,奇怪的是这个词的正确说法......
标签: python ssl python-requests openssl pyinstaller