I am trying to create an executable from a python project with pyinstaller. However, when I run the executable, it just opens and closes immediately. I don't get one error and two warnings when running pyinstaller from the command line. There are no error messages when running the executable.
(But I don't think that the two warnings should be problematic as I've created other executables with those same warnings and they still worked fine!!)
When I run
pyinstaller --debug=all main.py
I get
12070 WARNING: Hidden import "pkg_resources.py2_warn" not found!
12070 WARNING: Hidden import "pkg_resources.markers" not found!
...
Traceback (most recent call last):
File "[path]/venv/bin/pyinstaller", line 10, in <module>
sys.exit(run())
File "[path]/venv/lib/python3.9/site-packages/PyInstaller/__main__.py", line 126, in run
run_build(pyi_config, spec_file, **vars(args))
File "[path]/venv/lib/python3.9/site-packages/PyInstaller/__main__.py", line 65, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "[path]/venv/lib/python3.9/site-packages/PyInstaller/building/build_main.py", line 815, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "[path]/venv/lib/python3.9/site-packages/PyInstaller/building/build_main.py", line 762, in build
exec(code, spec_namespace)
File "[path]/main.spec", line 37, in <module>
coll = COLLECT(exe,
File "[path]/venv/lib/python3.9/site-packages/PyInstaller/building/api.py", line 855, in __init__
self.__postinit__()
File "[path]/venv/lib/python3.9/site-packages/PyInstaller/building/datastruct.py", line 159, in __postinit__
self.assemble()
File "[path]/venv/lib/python3.9/site-packages/PyInstaller/building/api.py", line 883, in assemble
os.makedirs(todir)
File "/usr/local/Cellar/python@3.9/3.9.1_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/os.py", line 225, in makedirs
mkdir(name, mode)
NotADirectoryError: [Errno 20] Not a directory: '[path]/dist/main/main/GUI'
When I now run
pyinstaller --hidden-import pkg_resources.py2_warn --hidden-import pkg_resources.markers --debug=all main.py
I get
11705 ERROR: Hidden import 'pkg_resources.py2_warn' not found
11705 ERROR: Hidden import 'pkg_resources.markers' not found
...
Traceback (most recent call last):
File "[path]/venv/bin/pyinstaller", line 10, in <module>
sys.exit(run())
File "[path]/venv/lib/python3.9/site-packages/PyInstaller/__main__.py", line 126, in run
run_build(pyi_config, spec_file, **vars(args))
File "[path]/venv/lib/python3.9/site-packages/PyInstaller/__main__.py", line 65, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "[path]/venv/lib/python3.9/site-packages/PyInstaller/building/build_main.py", line 815, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "[path]/venv/lib/python3.9/site-packages/PyInstaller/building/build_main.py", line 762, in build
exec(code, spec_namespace)
File "[path]/main.spec", line 37, in <module>
coll = COLLECT(exe,
File "[path]/venv/lib/python3.9/site-packages/PyInstaller/building/api.py", line 855, in __init__
self.__postinit__()
File "[path]/venv/lib/python3.9/site-packages/PyInstaller/building/datastruct.py", line 159, in __postinit__
self.assemble()
File "[path]/venv/lib/python3.9/site-packages/PyInstaller/building/api.py", line 883, in assemble
os.makedirs(todir)
File "/usr/local/Cellar/python@3.9/3.9.1_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/os.py", line 225, in makedirs
mkdir(name, mode)
NotADirectoryError: [Errno 20] Not a directory: '[path]/dist/main/main/GUI'
I've been stuck at this problem for days and at this point I really don't know what to do!
My system specs:
I am running everything in a virtual environment.
My project structure is:
Project
|- dist
|- build
|- main.spec
|
|- main.py
|- main
| |- GUI
| |- MainWindow.py
| |- ui.py
| |- Sim
| |- Setter.py
| |- Integrator.py
The executable works now after I changed the name of the directory main
from main
to MainPackage
.
I think the error was that my entry-point main.py
had the same name as the directory main
(which contains the other code that is called). So pyinstaller confused the directory with the entry-point file.
Also, I didn't have to include the two hidden imports for the executable to work (as suspected). The command to build the executable is simply:
pyinstaller main.py