1

I have a gui ocr application in python. Script runs successfully. However when I build it via pyinstaller with the command below,

python -m PyInstaller --upx-dir='D:\upx-3.96-win64' --paths=Baris --add-data './images;images' --collect-all easyocr --onedir -w main.py

When I run the .exe , gui opens as expected but imread of skimage library fails with the following error. So far, I have tried onefile argument, reinstalled the libraries such imageio, scikit-image, skimage but nothing changed. Are there any suggestions? Thanks.

Error line in code:

from skimage import io    

img = io.imread(img_file)

Error in runtime:

Traceback (most recent call last):
  File "main.py", line 422, in <module>
  File "main.py", line 209, in main
  File "main.py", line 83, in Resnet
  File "starter.py", line 180, in coreResnet
  File "starter.py", line 145, in runResnet
  File "text_detection2\resnet_detection.py", line 147, in run
  File "text_detection2\imgproc.py", line 13, in loadImage
  File "skimage\io\_io.py", line 53, in imread
    img = call_plugin('imread', fname, plugin=plugin, **plugin_args)
  File "skimage\io\manage_plugins.py", line 207, in call_plugin
    return func(*args, **kwargs)
  File "skimage\io\_plugins\imageio_plugin.py", line 10, in imread
    return np.asarray(imageio_imread(*args, **kwargs))
  File "imageio\__init__.py", line 86, in imread
  File "imageio\v2.py", line 159, in imread
  File "imageio\core\imopen.py", line 333, in imopen
ValueError: Could not find a backend to open `D:\Users\baris\PycharmProjects\Project - Kopya (3)\dist\main\images\3.png`` with iomode `ri`.
Based on the extension, the following plugins might add capable backends:
  pillow:  pip install imageio[pillow]
  PNG-PIL:  pip install imageio[pillow]
  PNG-FI:  pip install imageio[freeimage]
  ITK:  pip install imageio[simpleitk]
  • Try to manually include a backend when calling `PyInstaller` https://pyinstaller.readthedocs.io/en/stable/usage.html#cmdoption-collect-all – chill0r Mar 22 '22 at 14:22
  • @chill0r thank you for the quick reply, but nothing changed after I included a backend manually. – B. Kerem Kurt Mar 22 '22 at 17:16

1 Answers1

1

ImageIO dynamically imports plugins on demand. This minimizes loading time and improves platform compatibility (some backends cause problems on some OSes). Pyinstaller trips here, because it doesn't discover dynamic imports. As a result, you will have to manually specify the plugins/backends to include in your app when you build it with pyinstaller. You can read more about this here:

https://imageio.readthedocs.io/en/stable/user_guide/freezing.html

Alternatively, you can upgrade pyinstaller-hooks-contrib to the recently released pyinstaller-hooks-contrib==2022.3. The release updates pyinstaller to automatically include all of ImageIOs plugins (if a plugin's backend is installed in your environment during build time that is).

FirefoxMetzger
  • 2,880
  • 1
  • 18
  • 32