![](/img/trans.png)
[英]"distribution was not found and is required by the application" when using pyinstaller with setuptools
[英]Pyinstaller Error - “setuptools distribution was not found”
我正在尝试使用 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
任何帮助将不胜感激。 提前致谢。
这是由于 PyInstaller 未包含在最终.exe
文件中的一个包或一组文件。 当 PyInstaller 无法自动检测所需的模块或不是脚本的额外数据文件(因此不是您的导入和依赖项链的一部分)时,就会发生这种情况。
我无法从所提供的信息中透露更多信息,但可以提供一些一般性步骤。
.spec
文件并在其上运行 PyInstaller,而不是您的.py
文件。 在.py
文件上运行 PyInstaller 时,将首先创建.spec
文件,然后 PyInstaller 将从.spec
文件生成.exe
。
运行 PyInstaller 一次后,您可以手动编辑.spec
文件以包含 PyInstaller 无法自行找到的其他“隐藏”导入和直接资源/数据文件(如图像、元数据文件等)。
手动更新.spec
文件后,不要再在.py
文件上运行 PyInstaller。 相反,直接在.spec
文件上运行它,它将使用您手动指定的额外资源构建.exe
。
另请参阅有关与 PyInstaller 捆绑的实用程序的此答案,该实用程序可以为不同情况制作.spec
文件。
.spec
文件在规范文件中,有一个datas =
行,可以以非常特定的格式进行更新,以包含单个文件或整个文件夹及其内容。
如果 PyInstaller 缺少一些需要的导入(通常是因为特定包使用某种隐式的、非标准的方法来管理其一个或多个依赖项),您可以告诉.spec
文件中的.spec
无论如何都要包含它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.