Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python PyInstaller SSL错误,请求模块-缺少模块SSL(_SSL)_Python_Ssl_Python Requests_Openssl_Pyinstaller - Fatal编程技术网

Python PyInstaller SSL错误,请求模块-缺少模块SSL(_SSL)

Python PyInstaller SSL错误,请求模块-缺少模块SSL(_SSL),python,ssl,python-requests,openssl,pyinstaller,Python,Ssl,Python Requests,Openssl,Pyinstaller,在我的python脚本中,我使用请求模块调用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\PyInstal

在我的python脚本中,我使用请求模块调用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?

我在上一篇文章中搜索了很长时间,但所有这些答案都没有帮助,例如:

有人知道如何解决这个问题吗? 如果你需要更多的信息,请写评论。THX


编辑:(供月球陨石坑评论)

添加了python控制台的屏幕截图,输入:

import _ssl


编辑2:

测试了SO的“修复”问题:

->这并没有解决我的问题


编辑3:由cbolwerk回答

谢谢你的回答,这很有效

另外一个修复方法是安装最新的OpenSSL库,我在python脚本中使用了1.1.1h包,在我的PC上安装了较旧的版本,这也导致了错误


我在一台没有安装OpenSSL的PC上测试了cbolwerk的答案,正如我所写的,它可以工作

如果可以在环境中的python中导入ssl,则意味着ssl模块可能在环境中。提到您可以在环境中查找的文件。它们要么在您的env/Library/bin中,要么在env/dll中。我想您已经安装了这些,但是pyinstaller不识别它们。为了确保pyinstaller知道这些文件,您可以将它们添加到数据中。可以在生成.exe文件时在命令中进行编辑,也可以在运行此命令一次后可能创建的.spec文件中进行编辑。在那里可能有用

简而言之,将我提到的DLL的路径添加到数据中(实际上是.spec中的二进制文件),以便pyinstaller能够识别它们

所以要么运行命令

pyinstaller --onedir --add-data libcrypto-1_1-x64.dll;. --add-data libssl-1_1-x64.dll;. myscript.py
或者将您的.spec更改为

datas = [('/path/to/libcrypto-1_1-x64.dll', '.'), ('/path/to/libssl-1_1-x64.dll', '.'),
          (...) ]
...
a = Analysis(...,
             datas=datas,
             ...)
...
然后跑

pyinstaller --onedir myscript.spec

这至少解决了我的DLL问题。

@mooncarter我尝试了一个较旧的python版本,同样的问题@droebi在创建EXE时,您是否可以尝试使用Python 3.6.8添加
--hidden import pyodbc
?摘自答案。我以前也遇到过类似的问题。@mooncarter我尝试过这个修复,同样的问题:(…但非常感谢您迄今为止的支持,这是非常奇怪的。我特别坚持使用Python3.6.8+Pyinstaller组合,因为我认为这个原因。也许您也应该在Pyinstaller的repo页面上提出一个问题。这可能会导致一些问题。@mooncarter是的,这是一个正确的词…Thx作为回复,我会试试。bindi正在删除我的规范文件中的DLL
pyinstaller --onedir myscript.spec