Skip to content Skip to sidebar Skip to footer

Pyinstaller - Include Programmatically Imported Modules

I have a package that sort of looks like this: - package -- module1.py -- module2.py -- __init__.py In init.py I am programmatically scanning the package and importing

Solution 1:

This isn't an answer but is the only way I can show some code - this is my hook file for package mypkg, in the hooks folder, called hook-mypkg.py

import os

imports = []

for root, dirs, files inos.walk(os.path.join(os.getcwd(),"mypkg" )):
    print(root)
    for file in files:
        if file.endswith( ".py") andnot file.endswith( "__init__.py"):
            print( "  ",file)
            imports.append("mypkg."+file[:-3])
    print( "........." )
print( "hi=",imports )

hiddenimports = imports

This definitely works to include the .py files it finds in the bundle - they appear in globals()['__loader__'].toc in init.py as e.g. "mypkg.file1" for module mypkg\file1.py when sys.frozen is True.

Note after editing the hook you have to delete the dist and build folders then re-run pyinstaller

Post a Comment for "Pyinstaller - Include Programmatically Imported Modules"