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

ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running #179

Open
ALPHAX28 opened this issue Jun 14, 2024 · 3 comments

Comments

@ALPHAX28
Copy link

ALPHAX28 commented Jun 14, 2024

while importing from sort.sort import * ... i am getting this error...can anyone tell me how to fix it...i am using google colab

@Emrecangok
Copy link

did you find the solution?

@ALPHAX28
Copy link
Author

nope

@christian-post
Copy link

christian-post commented Oct 23, 2024

If you are not running sort.py as __main__ (i.e., from the command line), you can just comment out line 23 matplotlib.use('TkAgg') and it should work fine.

A possible, more elegant fix would be something like

try:
    import matplotlib
    matplotlib.use("TkAgg") 
except ImportError as e:
    if "TkAgg" in str(e):
        print("Switching to 'Agg' backend because TkAgg cannot be loaded in headless mode.")
        matplotlib.use("Agg")

but I haven't tested this yet since I don't need the plotting part.

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

3 participants