Reputation: 1
So I am trying to build a GUI app and works well, so I decided to turn it into an exe. but got the good old error at runtime, which after some research I identified as a problem with one of the libraries I use utilise dynamic imports. I made an MRE:
import hyperspy.api as hs
import tkinter as tk
root = tk.Tk()
s = hs.signals.Signal1D([0.])
label = tk.Label(root, text='data Loaded?')
label.pack()
imported =tk.Label(root, text='YES')
imported.pack()
root.mainloop()
and I use:
pyinstaller main.py
so the library in question is hyperspy and I actually just use a small portion of it but recreating that would be a pain. It uses dynamic imports left and right which makes sense I guess because it is a large library.
so when I package it, I get errors at runtime, basically because pyintstaller doesn't package it into _internal at all.
If I try hidden imports, I get an error during packaging that does submodules don't exist.
If I use --add-data:path;folder ->it seems to work partially, but then again there is an issue with dependencies at runtime.
I tried also to change the init.py-s in the hyperspy directory but that didn't work either.
What is my best solution? I know pyinstaller doesn't work with importlib, but all the workarounds I saw online don't seem to work.
Upvotes: 0
Views: 33
Reputation: 1
I found a workaround. If I add the whole module as additional data, but exclude it from normal import, then handle every single error that pops up at runtime, it works. Not sure if makes the app load slower or faster but at least it works.
Upvotes: 0