I'd like to deploy a one-directory .exe on Windows 10 based on a python application. I utilize PyInstaller for this purpose. I need skl2onnx ( a package related to the conversion of machine-learning models ) to be imported in the code. The relevant line inside one of my .py files looks as follows:
import skl2onnx
Running my main .py from PowerShell functions without any errors.
The path pointing to the package location resambles this:
C:\Users\User\Anaconda3\Lib\site-packages\skl2onnx
After launching the .exe the following message is being displayed:
import skl2onnx
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
File "skl2onnx\__init__.py", line 15, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
File "skl2onnx\convert.py", line 6, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
File "skl2onnx\common\_topology.py", line 38, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
File "skl2onnx\common\_container.py", line 95, in <module>
File "skl2onnx\common\_container.py", line 49, in _get_operation_list
File "inspect.py", line 1024, in getsource
File "inspect.py", line 1006, in getsourcelines
File "inspect.py", line 835, in findsource
OSError: could not get source code
[7712] Failed to execute script 'ParentWindow' due to unhandled exception!
I used a flag with PyInstaller:
--hidden-import=skl2onnx
I expected the modul to load succesfully before having checked the absence of the .dll (.pyd) equivalent pack of skl2onnx inside the PyiInstaller-generated dist folder, because running my main .py from PowerShell functions without any errors. Is loading skl2onnx in a dynamical manner via the importlib package a workaround?