gpt4 book ai didi

python - Pyinstaller 错误 - "setuptools distribution was not found"

转载 作者:行者123 更新时间:2023-12-04 15:54:58 24 4
gpt4 key购买 nike

我正在尝试使用 PyInstaller 为我的 Python 项目构建可执行二进制文件。

环境详情:

Python - 2.7.6,pip - 6.1.1,setuptools - 21.2.1

我可以成功构建项目:

pyinstaller heatstackapp.py
......
......
83093 INFO: checking COLLECT
83093 INFO: Building COLLECT because out00-COLLECT.toc is non existent
83094 INFO: Building COLLECT out00-COLLECT.toc
jayaprakash@cloudenablers:/opt/core/heatstack/heatstack$

但是当我执行二进制文件时,它会抛出以下错误消息:
jayaprakash@cloudenablers:/opt/core/heatstack/heatstack$     ./dist/heatstackapp/heatstackapp 
......
......
File "pbr/packaging.py", line 31, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "setuptools/command/develop.py", line 11, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "setuptools/command/easy_install.py", line 53, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "setuptools/package_index.py", line 206, in <module>
File "pkg_resources/__init__.py", line 943, in require
File "pkg_resources/__init__.py", line 829, in resolve
pkg_resources.DistributionNotFound: The 'setuptools' distribution was not found and is required by the application
Failed to execute script heatstackapp

任何帮助,将不胜感激。提前致谢。

最佳答案

这是由于最终 .exe 中未包含一个包或一组文件。 PyInstaller 的文件。当 PyInstaller 无法自动检测所需的模块或不是脚本的额外数据文件(因此不是导入和依赖链的一部分)时,就会发生这种情况。

我无法从所提供的信息中了解更多信息,但可以给出一些一般性步骤。

更新 .spec文件并在其上运行 PyInstaller,而不是您的 .py文件。

当您在 .py 上运行 PyInstaller 时文件,一个 .spec首先创建文件,然后 PyInstaller 将生成 .exe来自 .spec文件。

运行一次 PyInstaller 后,您可以编辑 .spec手动文件以包含 PyInstaller 无法自行找到的其他“隐藏”导入和直接资源/数据文件(如图像、元数据文件等)。

手动更新 .spec 后文件,不要在 .py 上运行 PyInstaller文件了。相反,直接在 .spec 上运行它文件,它将构建 .exe使用您手动指定的额外资源。

另见 this answer on a utility bundled with PyInstaller that can make a .spec file for different cases .

将数据文件添加到 .spec文件

在规范文件中,有一个 datas =可以以非常特定的格式更新以包含单个文件或整个文件夹及其内容的行。

  • this Q&A了解更多信息。
  • PyInstaller Docs on Using Spec Files

  • 隐藏的进口

    如果 PyInstaller 缺少一些需要的导入(通常是因为一个特定的包正在使用一些隐式的、非标准的方法来管理它的一个或多个依赖项),你可以在 .spec 中告诉 PyInstaller文件无论如何都要包含它。

    PyInstaller Docs on Hidden Imports .

    关于python - Pyinstaller 错误 - "setuptools distribution was not found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37428613/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com