Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing plugin with imread in SKIMAGE #510

Closed
chaoxinzheng opened this issue Feb 17, 2018 · 9 comments
Closed

Missing plugin with imread in SKIMAGE #510

chaoxinzheng opened this issue Feb 17, 2018 · 9 comments
Labels
good first issue Good for newcomers

Comments

@chaoxinzheng
Copy link

chaoxinzheng commented Feb 17, 2018

Building script with SKIMAGE as below:

import os
from skimage import io
import skimage
from skimage.viewer import ImageViewer
import sys
from tkinter import *
import PIL
from PIL import Image as PILImage
import PIL.ImageTk as imagetk
import tkinter.filedialog

path = tkinter.filedialog.askopenfilename()
moon = io.imread(path)
imviewer = ImageViewer(moon)
imviewer.show()

The above script works while in Spyder but generating the below error after building with Pyinstaller

Traceback (most recent call last):
  File "imread_example.py", line 13, in <module>
  File "site-packages\skimage\io\_io.py", line 61, in imread
  File "contextlib.py", line 77, in __exit__
  File "site-packages\skimage\io\util.py", line 36, in file_or_url_context
  File "site-packages\skimage\io\_io.py", line 61, in imread
  File "site-packages\skimage\io\manage_plugins.py", line 198, in call_plugin
RuntimeError: No suitable plugin registered for imread.

You may load I/O plugins with the `skimage.io.use_plugin` command.  A list of all available plugins are shown in the `skimage.io` docstring.

I have tried solution from this link, but not working.

https://stackoverflow.com/questions/40676027/pyinstaller-valueerror-too-many-values-to-unpack?noredirect=1&lq=1

It indicates that the library cannot be found.

@DongChen06
Copy link

hi, have you solved it?

@htgoebel
Copy link
Member

You need to add the required plugins using --hidden-import.

The stackoverflow solution is wrong since you want to add python modules (I assume) and no data-files.

@htgoebel
Copy link
Member

We would appreciate if you'd submit a hook for this. See https://pyinstaller.readthedocs.org/en/latest/hooks.html for more information about how to implement hooks.

@htgoebel htgoebel added the good first issue Good for newcomers label Feb 28, 2018
@chaoxinzheng
Copy link
Author

chaoxinzheng commented Feb 28, 2018

I solve this by using the solution from pyinstaller/pyinstaller#583

first put these at the top of the spec file:

_from distutils.sysconfig import get_python_lib
from os import path
skimage_plugins = Tree(
path.join(get_python_lib(), "skimage","io","_plugins"),
prefix=path.join("skimage","io","plugins"),
)

then i added 'skimage_plugins' the so it looks like below:

coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
skimage_plugins,
strip=False,
upx=True,
name='whatevername')

although i am facing other issues at the moment, but at least i got away with the error.

don't follow the stackoverflow solution. it was incorrect. not sure why it was given a tick.

@htgoebel
Copy link
Member

htgoebel commented Sep 1, 2018

Somebody to create a real hook for this?

You just need to use collect_data or collect_submodules (please check the other hooks for which one and test) to collect the plugins.

@htgoebel htgoebel reopened this Sep 1, 2018
@chaoxinzheng
Copy link
Author

chaoxinzheng commented Sep 2, 2018 via email

@HoLuLuLu
Copy link

HoLuLuLu commented Dec 11, 2018

You can create a hook file hook-skimage.io.py with the following content:

from PyInstaller.utils.hooks import collect_data_files, collect_submodules

datas = collect_data_files("skimage.io._plugins")`
hiddenimports = collect_submodules('skimage.io._plugins')

From: https://stackoverflow.com/a/35043355

Method 1: (global)

You have to do this method only one time. Your PyInstaller will use the file every time you have a project with skimage.io.
Copy the file in the hooks-folder of your PyInstaller directory (for me it is in ~/.local/lib/python3.6/site-packages/PyInstaller on Ubuntu, C:\Users\username\AppData\Local\Programs\Python\Python36\Lib\site-packages\PyInstaller on Windows).
Now PyInstaller includes the _plugin-folder of your skimage.io package into the generated directory/file and all I/O-operations with skimage will work correctly.

Method 2: (only for current project)

This method is NOT global. Your PyInstaller need to get this file every time you have a project with skimage.io.
Copy the file in a folder near to your project files e.g. hooks.
Then you start PyInstaller use the --additional-hooks-dirattribute like this:

pyinstaller --additional-hooks-dir=./hooks script.py

./hooks must the path to the folder there your hook-skimage.io.py is placed. script.py is your script with the application you want to pack with PyInstaller. You have to call this attribute every time you want to pack this script.

Both methods work for one-file and one-directory mode.
I recommend to use method 1.

I uploaded the file here:
https://drive.google.com/open?id=17Gg3AP000UnxTfIc0PV7wy4IJ15MhTqb

hook-skimage.io.zip

@bwoodsend bwoodsend transferred this issue from pyinstaller/pyinstaller Nov 4, 2022
@GenevieveBuckley
Copy link

Should this issue be closed now that pyinstaller/pyinstaller#3934 is merged?

@bwoodsend
Copy link
Member

So it can

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

6 participants