2

Using PyInstaller I created a executable from a python script as follows:

pyinstaller --onefile pythonScriptName.py

However, when I run the executable I get an error ImportError: No module named 'MyModule'. 'MyModule' is a placeholder name for a custom module I use in the script. So I'm assuming that PyInstaller didn't package up the custom modules. Is there some way to get it to do that?

the_pied_shadow
  • 337
  • 1
  • 4
  • 10
  • Where is you custom module located ? If it's being imported in `pythonScriptName.py`, then you can tell pyinstaller to search for it in any additional folders using `--paths "/location/of/folder"`. If it's not visible through any import statement, you could also use `--hidden-import modulename` along with this... – gdcodes Dec 18 '21 at 03:55
  • This discussion says the same things too https://stackoverflow.com/questions/15114695/imported-module-not-found-in-pyinstaller The question is for windows, but these flags aren't platform specific and have worked for me on macOS as well – gdcodes Dec 18 '21 at 03:55

1 Answers1

1

I found the --collect-submodules flag to be helpful when getting an import module error. I just specify the folder name under which all my modules are and pyinstaller collects all the imports automatically. something like this:

pyinstaller --collect-submodules <folder-name> 
nirlevywm
  • 86
  • 5