Pyinstaller.exe 读取图像失败

发布于 2025-01-16 01:45:21 字数 1730 浏览 5 评论 0原文

我有一个 python 中的 gui ocr 应用程序。脚本运行成功。但是,当我使用下面的命令通过 pyinstaller 构建它时,

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

当我运行 .exe 时,gui 按预期打开,但 skimage 库的 imread 失败并出现以下错误。到目前为止,我已经尝试过 onefile 参数,重新安装了 imageio、scikit-image、skimage 等库,但没有任何改变。有什么建议吗?谢谢。

代码中的错误行:

from skimage import io    

img = io.imread(img_file)

运行时错误:

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]

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]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

dawn曙光 2025-01-23 01:45:21

ImageIO 根据需要动态导入插件。这可以最大限度地减少加载时间并提高平台兼容性(某些后端会在某些操作系统上导致问题)。 Pyinstaller 会在这里出错,因为它没有发现动态导入。因此,当您使用 pyinstaller 构建应用程序时,您必须手动指定要包含在应用程序中的插件/后端。您可以在这里阅读更多相关信息:

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

或者,您可以将 pyinstaller-hooks-contrib 升级到最近发布的pyinstaller-hooks-contrib==2022.3。该版本更新了 pyinstaller 以自动包含所有 ImageIOs 插件(如果在构建期间在您的环境中安装了插件的后端)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文