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

No working GUI backend found for matplotlib #418

Open
stumarcus314 opened this issue Jan 15, 2019 · 16 comments
Open

No working GUI backend found for matplotlib #418

stumarcus314 opened this issue Jan 15, 2019 · 16 comments

Comments

@stumarcus314
Copy link

stumarcus314 commented Jan 15, 2019

I am getting the above warning when I try to use PyPlot for plotting and no plots show up. I followed the instructions here (#219), but it still didn't fix the issue when I try to call the Julia script which tries to use PyPlot. In the Julia terminal, after following those instructions, the warning does not show up but I also cannot get the basic example to show up. I use Julia v0.6.4 on MacOS. PyPlot used to work for me several months ago, and just tried to use it again today. I've done at least one Pkg.update() since the last time PyPlot worked.

@stumarcus314
Copy link
Author

stumarcus314 commented Jan 15, 2019

I installed XQuartz and logged out and logged back in, but still same warning. Should I Pkg.update() after installing XQuartz?

@stumarcus314
Copy link
Author

I tried the following, but still same error. I don't understand the instructions to install python.app, etc... Sounds complicated.

python
Python 2.7.14 |Anaconda custom (64-bit)| (default, Oct 5 2017, 02:28:52)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

import matplotlib.pyplot
Traceback (most recent call last):
File "", line 1, in
File "/Users/a598124/anaconda2/lib/python2.7/site-packages/matplotlib/pyplot.py", line 115, in
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/Users/a598124/anaconda2/lib/python2.7/site-packages/matplotlib/backends/init.py", line 62, in pylab_setup
[backend_name], 0)
File "/Users/a598124/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", line 17, in
from matplotlib.backends import _macosx
RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.

@stumarcus314
Copy link
Author

I looked at the instruction: https://matplotlib.org/faq/osx_framework.html
Should I install python.app via: conda install python.app
How do I use pythonw rather than python? Must Julia be signalled to use pythonw instead of python?

@tkf
Copy link
Member

tkf commented Jan 17, 2019

If you need to configure Python executable to be used from PyPlot.jl etc., you need to do it via PyCall.jl. See: https://github.com/JuliaPy/PyCall.jl#specifying-the-python-version

@stumarcus314
Copy link
Author

Can someone help me resolve this issue?

@stevengj
Copy link
Member

stevengj commented Feb 7, 2019

Maybe you have a .matplotlibrc file that is trying to use an unsupported backend. Try ENV["MPLBACKEND"]="tkagg"

@stumarcus314
Copy link
Author

When I tried the following, I get "Warning: No working GUI backend found for matplotlib"

using PyPlot
ENV["MPLBACKEND"]="tkagg"
x = linspace(0,2*pi,1000)
y = sin.(3 * x + 4 * cos.(2 * x))
plot(x, y, color="red", linewidth=2.0, linestyle="--")
title("A sinusoidally modulated sinusoid")

@KestutisMa
Copy link

PyPlot not working on Julia v1.1 (on Linux):
using PyPlot; plot(rand(10)) - no figure
On Windows same code shows figure.

p.s. on Linux Julia show() command gives: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.

@stevengj
Copy link
Member

stevengj commented Apr 9, 2019

You need ENV["MPLBACKEND"]="tkagg" etc. before using PyPlot if you want it to affect the backend.

@stevengj
Copy link
Member

stevengj commented Apr 9, 2019

@KestutisMa, what are PyPlot.backend and PyPlot.PyCall.python?

You could try using ENV["MPLBACKEND"]="tkagg" to specify a different backend (e.g. tkagg, qt5agg, gtkagg, …)

@KestutisMa
Copy link

KestutisMa commented Apr 10, 2019

Thanks for reply, Steven. I tried but still no plot window, but now I don't get warning message.

julia> ENV["MPLBACKEND"]="qt5agg"; using PyPlot; PyPlot.plot(rand(10)); PyPlot.ion(); PyPlot.show()

julia>

@KestutisMa
Copy link

I just figured out: I need to do pygui(true) now I got figure shown! :-)

@stumarcus314
Copy link
Author

ENV["MPLBACKEND"]="tkagg"
using PyPlot
pygui(true)

The above lines in the Julia command window give: ERROR: No working GUI backend found for matplotlib.
Stacktrace:
[1] pygui(::Bool) at /Users/a598124/.julia/v0.6/PyPlot/src/init.jl:222

PyPlot.backend is "Agg" and PyPlot.PyCall.python is "/Users/a598124/.julia/v0.6/Conda/deps/usr/bin/python".

@MaxandreJ
Copy link

I just figured out: I need to do pygui(true) now I got figure shown! :-)

This solved my problem. It seems that unlike the previous versions, calling pygui(true) is now necessary to have interactive figures displayed, even if the matplotlib backend is correctly set.

The error I had

/Users/maxandrejacqueline/anaconda3/envs/snakes/lib/python3.7/site-packages/matplotlib/figure.py:445: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
  % get_backend())

Could perhaps be amended to be more informative? Ideally, it should distinguish the case that pygui(true) hasn't been called and that when the backend of matplotlib is not correctly set.

@stevengj
Copy link
Member

You only need pygui(true) to get interactive figures if you are running in a Jupyter notebook, because in Jupyter PyPlot defaults to inline display. This has always been the case.

If you run from a REPL, it defaults to interactive figures and there is no need to call pygui(true).

@jjstickel
Copy link

Although this is old (but still "open"), I'm posting here because this was the top link when I googled my problem. I'm using macports' installed python, matplotlib, and pyqt5 on an M2 Mac. Despite having backend : QtAgg in my matplotlibrc file (and plotting working fine from an ipython shell), I was experiencing this in Julia:

julia> using PyCall

julia> pygui()
:tk

julia> pygui(:qt)
:qt

julia> using PyPlot
┌ Warning: No working GUI backend found for matplotlib
└ @ PyPlot ~/.julia/packages/PyPlot/2MlrT/src/init.jl:153

It turns out that pygui(:qt) is not sufficient, but rather pygui(:qt5)! It also works to use ENV["MPLBACKEND"]="Qt5Agg" in startup.jl. Hope this helps someone else.

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

6 participants