Search code examples
pythonimportpyinstaller

PyInstaller failing to include some modules from C:\Python27\Lib


I've been repeatedly making good PyInstaller executables of a Tkinter utility program, and suddenly this morning the resulting executable fails with a "can't import" error for modules in C:\Python27\Lib, such as "timeit" and "bisect".

The script runs fine on its own. Only the executable has problems.

Any ideas what could have changed to cause this behavior? Or how to force a fix?

[EDIT] Here's the specific error reported by the executable:

Traceback (most recent call last):
  File "<string>", line 35, in <module>
  File "../..\utils\InterpolatedArray.py", line 12, in <module>
    import bisect
ImportError: No module named bisect

When I comment-out the use of this module (to bypass the import of bisect), it next fails on an import of timeit. None of these errors occur when running the script itself.

[EDIT2] Pyinstaller creates the directories it needs (./build and ./dist), and has no permission problems. The pyinstaller build completes without error.

[EDIT3] Here's the build command I'm using:

pyinstaller -F MyMainModule.py

Solution

  • Found a fix, if not the cause. Here's my updated build line:

    pyinstaller --hidden-import=timeit --hidden-import=bisect -F MyMainModule.py
    

    Still not sure why PyInstaller suddenly forgot how to find these two modules (and only these two modules) among over 20 other modules correctly included in the build.