Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
I wrote a programm using the skimage library (
from skimage.metrics import structural_similarity
). It works just fine, also creating the .exe using PyInstaller (
pyinstaller name.py --debug=all -c --icon=icon.png --onefile
) shows no errors.
When executing the .exe via cmd however, the following Error log shows up:
Traceback (most recent call last):
File "label_check.py", line 8, in <module>
from skimage.metrics import structural_similarity
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
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 "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "skimage\__init__.py", line 74, in <module>
File "lazy_loader\__init__.py", line 245, in attach_stub
ValueError: Cannot load imports from non-existent stub 'C:\\Users\\hartpude\\AppData\\Local\\Temp\\_MEI167882\\skimage\\__init__.pyi'
[9492] Failed to execute script 'label_check' due to unhandled exception!
[9492] LOADER: OK.
[9492] LOADER: Manually flushing stdout and stderr
[9492] LOADER: Cleaning up Python interpreter.
So the problem seems to be the import of skimage.metrics.
I have tried using including the hidden import
--hidden-import=skimage
/
--hidden-import=skimage.metrics
and after some research I added a hook file "hook-scikit-image.py" to the directory containing the following, according to the source
https://github.com/pyinstaller/pyinstaller-hooks-contrib/blob/master/src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-skimage.data.py
:
# ------------------------------------------------------------------
# This file is distributed under the terms of the GNU General Public
# License (version 2.0 or later).
# The full license is available in LICENSE.GPL.txt, distributed with
# this software.
# SPDX-License-Identifier: GPL-2.0-or-later
# ------------------------------------------------------------------
from PyInstaller.utils.hooks import is_module_satisfies, collect_data_files, collect_submodules
# As of scikit-image 0.20.0, we need to collect the __init__.pyi file for `lazy_loader`, as well as collect submodules
# due to lazy loading.
if is_module_satisfies('scikit-image >= 0.20.0'):
datas = collect_data_files("skimage.data", includes=["*.pyi"])
hiddenimports = collect_submodules('skimage.data', filter=lambda name: name != 'skimage.data.tests')
I included it via: pyinstaller label_check.py --debug=all -c --icon=icon.png --onefile --additional-hooks-dir=C:\...path...\hook-scikit-image.py
but still the same error occurs. I also noticed this just above the Error log posted above:
import 'skimage._shared.version_requirements' # <_frozen_importlib_external.SourcelessFileLoader object at 0x00000211562526A0>
\# lazy_loader not found in PYZ
\# code object from 'C:\\Users\\myusername\\AppData\\Local\\Temp\\_MEI167882\\lazy_loader\\__init__.pyc'
import 'lazy_loader' # <_frozen_importlib_external.SourcelessFileLoader object at 0x0000021156252880>
It seems like I am not the first one having the problem but the link in this thread unfortunately did not help me solve my issue: https://groups.google.com/g/pyinstaller/c/9trSWwpIh3E
It seems that my knowledge is not enough to undestand the maby already given solves and I would deeply appreciate any help, if more input is needed for that I am happy to provide it. Thank you in advance!
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.