首页 > 解决方案 > PyInstaller 生成的可执行文件中的 Python SSL 导入错误

问题描述

我正在尝试分发我创建的 Python 程序的可执行文件。为此,我正在使用PyInstaller

我使用带有 Python 3.7 的 Windows 7 Professional 该程序在 PyCharm 中成功运行并产生预期的结果。

如 PyInstaller 手册中所述,我创建了 dist 文件夹:

pyinstaller main.py

日志输出指定该过程已成功完成。

尝试main.exe从分发文件夹运行时,会产生以下错误:

Traceback (most recent call last):
  File "site-packages\PyInstaller\loader\rthooks\pyi_rth_certifi.py", line 11, i
n <module>
  File "c:\users\tim\anaconda3\envs\timtf2_37\lib\site-packages\PyInstaller\load
er\pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "ssl.py", line 98, in <module>
ImportError: DLL load failed: The specified procedure could not be found.
[6236] Failed to execute script pyi_rth_certifi

标签: pythonpyinstaller

解决方案


所以几个小时后,我设法解决了这个问题。我做了几件事,但仍然不确定实际修复的是什么,但这是我完成的分步流程:

  1. 使用 Anaconda 创建了一个新环境。我已将 Python 版本降级为 3.6.8,因为我看到有人提到 Python 3.7 存在一些兼容性问题
  2. 使用 Anaconda 安装了我的项目中的所有要求,因为有些提到混合使用pipconda.
  3. 安装了最新版本的pyinstaller.
  4. 激活新环境并pyinstaller在其中运行带有参数main.py的程序脚本。--hidden-import pyodbc

就是这样,现在分布式程序可以在办公室的所有 Windows 计算机上运行。


推荐阅读