Search code examples
pythoncompiler-errorspyinstallerttkwidgets

PyInstaller - ModuleNotFoundError in spite of hooks and hidden modules


I've looked everywhere (including the Pyinstaller Github and documentation) but nothing seems to force Pyinstaller to find the ttkwidgets module while compiling the software.

My script is on based on multiple layers, the 'main' file is on the upper layer :

main.py
hook-main.py
icon.ico
frames/
    __init__.py
    frame01.py
    frame02.py
submodules/
    __init__.py
    crawler.py
    importer.py
    export/
        exporter.py

Since the very first pyinstaller compiling I've had trouble with the ttkwidgets module. I've tried everything :

  • adding a --hidden-import=ttkwidgets to the pyinstaller prompt (full prompt : pyinstaller --hidden-import=ttkwidgets --noconsole -F --additional-hooks-dir=. main.py
  • creating a hook-main, with the collect_data_files and collect_submodules hooks modules, but nothing seems to work.

This is my hook file :

from PyInstaller.utils.hooks import collect_submodules
from PyInstaller.utils.hooks import collect_data_files

hiddenimports = [
    "tkinter",
    "ttkwidgets",
    "urllib",
    collect_submodules('ttkwidgets')
]

datas = collect_data_files (ttkwidgets)

I've even added the collect_data_files utils in the 'main.py' file and the 'frame02.py' file, but nothing seems to work.

I always find myself with an "unhandled exception in script" :

Traceback (most recent call last):
 File "main.py", line 13, in <module>
 File "Pyinstaller\loader\pyimod02_importers.py", line 385, in exec_module
 File "frames\_init_.py", line 2, in <module>
 File "PyInstaller\loader\pyimod02_importers.py", line 385, in exec_module
 File "frames\frame02.py", line 5 in <module>
ModuleNotFoundError: No module named 'ttkwidgets'

Solution

  • I was using Python 3.10, and moved to Python 3.11.3 which is much more stable for Pyinstaller, which solved the issue.