I'm trying to build an executable binary for my Python project using PyInstaller.
Environment Details:
Python - 2.7.6, pip - 6.1.1, setuptools - 21.2.1
I can build the project successfully:
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$
but when I execute the binary, it throws the following error message:
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
Any help would be appreciated. Thanks in advance.
This is due to a package or set of files that are not being included in the final .exe
file by PyInstaller. This happens when PyInstaller cannot automatically detect the modules needed, or extra data files that are not scripts (and therefore not a part of your chain of imports and dependencies).
I cannot tell more from the information provided, but can give some general steps to take.
.spec
file and run PyInstaller on it, rather than your .py
file.When you run PyInstaller on your .py
file, a .spec
file will first be created, then PyInstaller will generate the .exe
from the .spec
file.
After running PyInstaller once, you can edit the .spec
file manually to include additional "hidden" imports and direct resource/data files (like images, metadata files, etc.) that PyInstaller can't find on it's own.
After manually updating the .spec
file, don't run PyInstaller on the .py
file anymore. Instead, run it directly on the .spec
file, and it will build the .exe
with the extra resources that you manually specified.
See also this answer on a utility bundled with PyInstaller that can make a .spec
file for different cases.
.spec
fileIn the spec file, there is a datas =
line that can be updated in a very specific format to include individual files or entire folders with their content.
If PyInstaller is missing some needed imports (usually because a particular package is using some implicit, non-standard method of managing one or more of its dependencies), you can tell PyInstaller in the .spec
file to include it anyway.
See PyInstaller Docs on Hidden Imports.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With