Skip to content

Improve error message when reading an EXR file without plugin installed #334

Closed

Description

@Overdrivr

It's just a minor thing, but if the EXR plugin is not installed, EXR images cannot be read and imageio.imread fails with this error message:

>>> img = imageio.imread(path)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\remib\.virtualenvs\qzMurbXh\lib\site-packages\imageio\core\functions.py", line 206, in imread
    reader = read(uri, format, 'i', **kwargs)
  File "C:\Users\remib\.virtualenvs\qzMurbXh\lib\site-packages\imageio\core\functions.py", line 126, in get_reader
    'in mode %r' % mode)
ValueError: Could not find a format to read the specified file in mode 'i'

All that is required to fix this is to run

imageio.plugins.freeimage.download()

Maybe this call should be mentioned in the error message ?

Activity

  1. almarklein commented on Apr 12, 2018

    @almarklein
    Member

    That would be much better indeed. Would not be trivial to add though. When the format manager iterates over the plugins to find one capable of handling a request, plugins can only say yes or no. For this to work we would need some sort of option to allow a plugin to say "no, but ...".

    I think this would be worth the effort, but this will have to wait for when I have/allocate some serieus imageio-time :)

  2. FirefoxMetzger commented on Nov 5, 2021

    @FirefoxMetzger
    Contributor

    I think we can fix this soon™ (via #680 ).

    If a user tries to read using iio.imread(..., format="EXR-FI") and FreeImage is not installed, it will ask the user to install FreeImage first.

    For files that have the .exr extension this will still give a generic error, but we can discuss/look into if this should raise a warning or error that it could be read after installing FreeImage.

  3. FirefoxMetzger commented on Nov 7, 2021

    @FirefoxMetzger
    Contributor

    Okay, this will get fixed in #680.

    If no currently installed backend can fulfill the request we check the image resource for its extension. If it has an extension, we look up all plugins that are associated with this extension and check if they are installed. For each missing plugin, we inform the user in the error message that installing that plugin might resolve this error.

    This should turn the above exception into something like:

    img = imageio.imread(path)
    ...
    OSError: Could not find a backend to open `path` with iomode `r`. Based on the extension, the following plugins might add capable backends:
      EXR-FI: pip install imageio[freeimage]
    

    @almarklein What do you think?

  4. almarklein commented on Nov 12, 2021

    @almarklein
    Member

    Sounds good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions