I apologize now for the long post.
I am working on converting a Hello World program from a Python file to a stand-alone, distributable executable file, using pyinstaller. I am using pyinstaller 3.6, on Windows 10 Enterprise. Python code was written using Spyder 4.0.1 (I am currently unable to update to 4.1.3).
I have created the HelloWorld.py file:
#! python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 30 12:27:20 2020
@author: DNICHOL3
"""
def main():
print("Hello World!")
if __name__ == "__main__":
main()
As well as a cli.py file in the same folder:
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 30 09:07 2020
@author: DNICHOL3
"""
# import HelloWorld
from HelloWorld.__main__ import main
if __name__ == '__main__':
main()
I am running pyinstaller with the –onefile –debug imports –clean flags:
pyinstaller cli.py –onefile –debug imports --clean
I then run cli.exe from the dist folder, and get several screens of output (import xxx, # clear yyy, # restore zzz, # cleanup [2] aaa). Embedded in this output are the following lines:
HelloWorld not found in PYZ
Traceback (most recent call last):
File “cli.py”, line 10, in <module>
File “<frozen importlib.bootstrap>”, line 991, in _find_and_load
File “<frozen importlib.bootstrap>”, line 961, in _find_and_load_unlocked
File “<frozen importlib.bootstrap>”, line 219, in _call_with_frames_removed
File “<frozen importlib.bootstrap>”, line 991, in _find_and_load
File “<frozen importlib.bootstrap>”, line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named ‘HelloWorld’
[21600] Failed to execute script cli
Looking at warn-cli.txt shows that HelloWorld is indeed missing:
Missing module named ‘HelloWorld.__main__’ imported by C:\Users\dnichol3\python\Utilities\cli.py (top-level)
and cli.spec seems to show that HelloWorld is missing from PYZ:
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
Executing the generated cli.exe encounters the error message:
File “cli.py”, line 10, in <module>
ModuleNotFoundError: No module named ‘HelloWorld’
I have gone through the pyinstaller documentation (When Things Go Wrong). I have attempted to include HelloWorld.py into my pyinstaller command by using the –hidden_import flag, but that consistently ends with pyinstaller: error: unrecognized arguments: --hidden_import. And it doesn’t matter whether or not I use an equal sign between hidden_import and HelloWorld, nor does it matter whether or not I use the .py file extension.
I tried some other Stack Overflow suggestions (https://stackoverflow.com/a/46894037/12344177, https://stackoverflow.com/a/41869771/12344177, and https://stackoverflow.com/a/47337389/12344177 ) to no avail. Any assistance would be appreciated.