1

I have a python file that I am trying to create an executable out of using Pyinstaller on my Mac. This python file imports several different python files. When I run the unix executable that was generated, I get this error:

  File "main/__init__.py", line 4, in <module>
  ModuleNotFoundError: No module named 'game'

Line 4 reads:

from game.scripts.gui import creator

The command I used to create the executable:

pyinstaller __init__.py --onefile --clean --windowed

The directory:

__init__.py
game
   scripts
       gui
          creator.py
             

Any ideas on how I could fix this? Thanks

Smarf
  • 75
  • 6

1 Answers1

0

The subdirs are not included by creating an *.exe, so the creator.py is not found inside your *.exe. To avoid that, you have to include the extra files/folders by specifying them. This can be done by a *.spec file

By calling pyinstaller with your *.py file it will create a default *.spec file which you can edit and use next time to create your *.exe. Every option you used when calling

pyinstaller __init__.py --onefile --clean --windowed

is configured here so calling

pyinstaller *.spec

the next time gives the same result.

Edit this in your spec-file to fit your needs by copying single files or even whole folders including their content into the *.exe:

a = Analysis(['your.py'],
             pathex=['.'],
             binaries=[],
             datas=[('some.dll', '.'),
                    ('configurationfile.ini', '.'),
                    ('data.xlsx', '.'),
                    ('../../anotherfile.pdf', '.')
                    ],
....some lines cut ....
a.datas += Tree('./thisfoldershouldbecopied', prefix='foldernameinexe')

More infos to that are found in the docs of pyinstaller regarding spec-files and including data files https://pyinstaller.readthedocs.io/en/stable/spec-files.html

and for example in this post here: Pyinstaller adding data files

flipSTAR
  • 579
  • 1
  • 4
  • 18