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

gmic-py prints exception on display-less system even without display command being invoked #99

Open
robin-pfeiffer opened this issue Jul 5, 2021 · 1 comment

Comments

@robin-pfeiffer
Copy link

robin-pfeiffer commented Jul 5, 2021

When running the following G'MIC commands on a display-less system (WSL Ubuntu 20.04), gmic-py (2.9.2 from PyPI) still prints a message out about not being able to display images because of missing matplotlib or ipython dependencies

import gmic; gmic.run("sp lena blur 10 output lena.png")

Outputs

gmic-py: Working in display-less mode.
gmic.GmicException: Could not use matplotlib neither ipython to try to display images
@robin-pfeiffer
Copy link
Author

robin-pfeiffer commented Jul 6, 2021

Maybe a setting to run G'MIC in a silent mode would be an option to pass to a G'MIC instance when creating one. That way, the stdout and stderr don't get polluted. I don't know if this is already possible, but I couldn't find anything in the documentation of gmic-py. Something like this would be helpful:

import gmic

gmicInstance = gmic.Gmic(silent=True)

As a temporary fix, I redirect both stdout for the display-less mode message and stderr for the dependencies' error while executing G'MIC commands like so:

import gmic
import contextlib
import io

f = io.StringIO()
with contextlib.redirect_stderr(f):
    with contextlib.redirect_stdout(f):
        gmic.run("sp lena blur 10 output lena.png")

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

No branches or pull requests

1 participant