For the program I'm writing, I set up a package which defines an interface for algorithms to convert CSV files from one format to another, scans the package directory for modules which implement the interface, then gives them to the importing program as a list[ModuleType], so that the importing program can list them in a dropdown and present them to the user. Here's the code I used to make the list of modules:
./conversionAlgos/__init__.py:
>>> algos: list[ModuleType] = sorted(
... [
... importlib.import_module("." + name, __name__)
... for _, name, _ in pkgutil.iter_modules(__path__)
... ],
... key=lambda item: item.PRIORITY,
... )
In my main.py that I package with pyinstaller I access the modules like this:
./main.py
>>> from conversionAlgos import algos
...
... for algo in algos:
... print(algo.Converter().friendly_name)
algorithm 1
algorithm 2
etc.
This works fine when I run the program a script, but because the package isn't laid out in the filesystem after I build it with pyinstaller, it can't find the modules. Is there a better way to make the list of modules that will be compatible with pyinstaller?