[Python] Matplotlib cannot switch backend to 'TkAgg', as 'qt' is currently running

Discussão em 'Python' iniciado por Stack, Fevereiro 26, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to display a plot in Pycharm Comunity Edition and I get the following error:


    UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so >cannot show the figure.
    ​

    I have installed and imported tkinter before importing matplotlib but I cannot make Matplotlib switch to 'TKAgg'.

    I tried running

    matplotlib.use('TKAgg', force=True)


    and

    plt.switch_backend('tkagg')


    and they both result in the following error:


    ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive >framework, as 'qt' is currently running
    ​

    I also tried adding MPLBACKEND=TkAgg to the environment variables but did not change anything.

    Does anyone have an idea what else I can do to solve this so that I can display graphs?

    Continue reading...

Compartilhe esta Página