python-3.x - Pyinstaller 可执行文件失败并出现 pkg_resources.DistributionNotFound 错误

标签 python-3.x pyinstaller

我正在使用 tkinter 制作 PDF 工具可执行文件。无论如何,可执行文件已由 pyinstaller 成功创建,但无法运行。我标记了 --onedir 并添加了必要的依赖文件 --add-data。我还使用 --paths 标志添加了非标准库包的路径。当我从命令提示符运行可执行文件时,我得到以下信息: enter image description here

问题似乎来自 ocrmypdf 模块并显示 pkg_resources.DistributionNotFound。我尝试寻找修复程序,但我看到的所有问题都与我的问题有所不同,因为 .py 脚本对我来说运行得很好。这是 pyinstaller 的问题,还是我缺少模块?我也在使用 pyinstaller 4.0。

最佳答案

经过一番研究,我找到了解决方案。问题出在 pyinstaller 上,而不是 ocrmypdf 模块上。解决方案是您必须在项目的文件夹中创建 hook py 脚本。根据您使用的模块的不同,情况略有不同,但对于这种情况,我必须在一个名为“hooks”的文件夹中创建两个 hook py 脚本。这是我制作的两个脚本:

hook-ocrmypdf.py

from PyInstaller.utils.hooks import collect_all

datas, binaries, hiddenimports = collect_all('ocrmypdf')

hook-pikepdf.py

from PyInstaller.utils.hooks import collect_all

datas, binaries, hiddenimports = collect_all('pikepdf')

欲了解更多信息,请访问here.

此外,您必须将 --additional-hooks-dir HookFolderPath 标志添加到 pyinstaller 命令中。

关于python-3.x - Pyinstaller 可执行文件失败并出现 pkg_resources.DistributionNotFound 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64468438/

相关文章:

python - 无法下载 Wordnet 错误

python - 我无法使用 Pyinstaller 打包我的程序,因为我安装了 enum34,无法卸载,因为已使用的模块需要它。有什么建议么?

python - Pyinstaller 在使用 matplotlib 时显示一些错误

python - 如何从脚本而不是终端使用 PyInstaller?

python - PyInstaller 无法添加 .txt 文件

python - 无法确定 turtle 运动的时间

google-app-engine - 适用于 Google App Engine 的 Python 3

python - 在 Python 3 中记录到多个文件

python-3.x - 卡在带有 urllib (python3) 的打开网址上

python - py 安装程序 numpy. EXE在运行时抛出错误