No working GUI backend found for matplotlib

Hi,

I am a new Julia user. I made a simple script to save figures. Note that here I don’t want to display each figure, but instead only to save them.

I tested the script on a local machine that is linux, and I also on a mac one and it is working fine. I them submitted the code on a remote server.

However, I am getting the error below.

Can you please help me to find a solution for it ?

Thank you in advance,

/home/josimar/.julia/v0.5/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/init.py:1401: UserWarning: This call to matplotlib.use() has no
effect
because the backend has already been chosen;
matplotlib.use() must be called before pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.

warnings.warn(_use_error_msg)
WARNING: No working GUI backend found for matplotlib
ERROR: LoadError: InitError: PyError (:PyImport_ImportModule) <type ‘exceptions.ImportError’>
ImportError(“/lib64/libz.so.1: version `ZLIB_1.2.3.4’ not found (required by /home/josimar/.julia/v0.5/Conda/deps/usr/lib/python2.7/site-packages/mat
plotlib/…/…/…/libpng16.so.16)”,)
File “/home/josimar/.julia/v0.5/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/pyplot.py”, line 29, in
import matplotlib.colorbar
File “/home/josimar/.julia/v0.5/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/colorbar.py”, line 36, in
import matplotlib.contour as contour
File “/home/josimar/.julia/v0.5/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/contour.py”, line 23, in
import matplotlib.text as text
File “/home/josimar/.julia/v0.5/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/text.py”, line 33, in
from matplotlib.backend_bases import RendererBase
File “/home/josimar/.julia/v0.5/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/backend_bases.py”, line 63, in
import matplotlib.textpath as textpath
File “/home/josimar/.julia/v0.5/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/textpath.py”, line 20, in
from matplotlib.mathtext import MathTextParser
File “/home/josimar/.julia/v0.5/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/mathtext.py”, line 62, in
import matplotlib._png as _png

in pyerr_check at /home/josimar/.julia/v0.5/PyCall/src/exception.jl:56 [inlined]
in pyerr_check at /home/josimar/.julia/v0.5/PyCall/src/exception.jl:61 [inlined]
in macro expansion at /home/josimar/.julia/v0.5/PyCall/src/exception.jl:81 [inlined]
in pyimport(::String) at /home/josimar/.julia/v0.5/PyCall/src/PyCall.jl:391
in init() at /home/josimar/.julia/v0.5/PyPlot/src/init.jl:189
in _include_from_serialized(::String) at ./loading.jl:150
in _require_from_serialized(::Int64, ::Symbol, ::String, ::Bool) at ./loading.jl:187
in _require_search_from_serialized(::Int64, ::Symbol, ::String, ::Bool) at ./loading.jl:217
in require(::Symbol) at ./loading.jl:371
in include_from_node1(::String) at ./loading.jl:488
in process_options(::Base.JLOptions) at ./client.jl:262
in _start() at ./client.jl:318
during initialization of module PyPlot

I haven’t been able to get this working on a cluster due to the same problem either. But the neat thing about Plots.jl is you just pick a different backend. The GR backend tends to work well on clusters.

thanks for the reply. I would use the GR backend, however, I just wrote a whole set of plots using the PyPlot backend, which worked fine on a local machine. I would rather not switch to GR unless there is no other alternative.

thank you.

Try specifying that you don’t want a GUI, by setting the environment variable MPLBACKEND=Agg You can do this in your Julia script with

ENV["MPLBACKEND"] = "Agg"
using PyPlot

@Ralph_Smith I never got that working on a cluster. For reference, here’s an issue with replies from the library developers trying to get each of these to work. It’s a pretty standard CentOS cluster with modules and SG etc., so it’s a good reference.

This is why Plots.jl should be the only recommended plotting library. Otherwise people get stuck in this trap if they get mislead to Gadfly or directly using PyPlot… the backend independence is just too central of a feature.

I tried the solution proposed above and it seems that the error now changed, see below. It seems that moving to GR from PyPlot is the only solution (?). It would have been good to know this before.

thank you for the help.

ERROR: LoadError: InitError: PyError (:PyImport_ImportModule) <type ‘exceptions.ImportError’>
ImportError(“/lib64/libz.so.1: version `ZLIB_1.2.3.4’ not found (required by /home/josimar/.julia/v0.5/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/…/…/…/libpng16.so.16)”,)
File “/home/josimar/.julia/v0.5/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/pyplot.py”, line 29, in
import matplotlib.colorbar
File “/home/josimar/.julia/v0.5/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/colorbar.py”, line 36, in
import matplotlib.contour as contour
File “/home/josimar/.julia/v0.5/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/contour.py”, line 23, in
import matplotlib.text as text
File “/home/josimar/.julia/v0.5/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/text.py”, line 33, in
from matplotlib.backend_bases import RendererBase
File “/home/josimar/.julia/v0.5/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/backend_bases.py”, line 63, in
import matplotlib.textpath as textpath
File “/home/josimar/.julia/v0.5/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/textpath.py”, line 20, in
from matplotlib.mathtext import MathTextParser
File “/home/josimar/.julia/v0.5/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/mathtext.py”, line 62, in
import matplotlib._png as _png

in pyerr_check at /home/josimar/.julia/v0.5/PyCall/src/exception.jl:56 [inlined]
in pyerr_check at /home/josimar/.julia/v0.5/PyCall/src/exception.jl:61 [inlined]
in macro expansion at /home/josimar/.julia/v0.5/PyCall/src/exception.jl:81 [inlined]
in pyimport(::String) at /home/josimar/.julia/v0.5/PyCall/src/PyCall.jl:391
in init() at /home/josimar/.julia/v0.5/PyPlot/src/init.jl:189
in _include_from_serialized(::String) at ./loading.jl:150
in _require_from_serialized(::Int64, ::Symbol, ::String, ::Bool) at ./loading.jl:187
in _require_search_from_serialized(::Int64, ::Symbol, ::String, ::Bool) at ./loading.jl:217
in require(::Symbol) at ./loading.jl:371
in include_from_node1(::String) at ./loading.jl:488
in process_options(::Base.JLOptions) at ./client.jl:262
in _start() at ./client.jl:318
during initialization of module PyPlot

What I am saying is that the most flexible solution is to use Plots.jl, so that way switching plotting libraries only takes one line and the rest of the syntax is left in place. Otherwise you’re open to issues like this.

ok got it. Thanks for the clarification. The concept of “Plots.jl” and “backends” are a little bit confusing for a beginner to Julia. There are some resources below to understand it better, however, feel free to suggest any other resources to add to the ones below.

https://en.wikibooks.org/wiki/Introducing_Julia/Plotting
https://juliaplots.github.io

See error loading ZLIB (wrong libz library being linked) · Issue #151 · JuliaPy/PyPlot.jl · GitHub … the problem is that it is finding the wrong libz.so library

It seems that both @ChrisRackauckas (in the Plots.jl issue mentioned above) and @josimar have encountered a library version conflict (this PyPlot issue, I think). That sort of difficult problem is always a risk when calling into Python packages with plentiful dependencies. If your sunk labor in PyPlot code justifies it, you might try workarounds described in the issue.

On the whole, I agree with @ChrisRackauckas - I have been having unpleasant experiences with the various Qt backends for PyPlot myself recently (also library conflicts), and am trying to use Plots.jl in my own projects now.

… as long as you find N>0 backends working on your platform. Even in your issue this only made working by effort spend on the GR installation.

Pretty strong statement. I have recently given Plots.jl a try and getting all the backends working was more work than simply using PyPlot.

Do you mean each individually or all of them? And what do you mean ‘simply’ using PyPlot - is that inherently a more simple thing to do in your opinion than using Plots?

Pkg.add(“PyPlot”)
using PyPlot

I had some issues getting Plotly and gr installed. I was able to solve the issues by some google search. But saying that Plots.jl is more intuitive or stable than PyPlot.jl is not a statement that I would sign.

It is just not quite balanced to compare getting one package to work (PyPlot) with getting every package that interfaces with Plots (which includes PyPlot!) to work. You have all the features of PyPlot with just

Pkg.add("PyPlot")
Pkg.add("Plots")
using Plots

In addition to this, Plots offers all the other backends, but they are at very different stages. The PlotlyJS backend is great, but not very actively maintained, GLVisualize super promising but not yet mature, GR as stable as Pyplot etc. Importantly, you don’t have to engage with any backend if you don’t need/want to .

If you prefer PyPlot that is completely great, I am just questioning the idea that it is inherently more simple.

No, I am absolutely fine that everybody uses whatever she/he wants. I have responded to

This statement pretty directly implies that PyPlot is not(!) a recommended plotting library. And I disagree.

That’s a fair point.
I just felt your response subtly did the same the other way :slight_smile: Apologies if you did not mean it like that.

It is a strong statement, because it’s what’s been found to be repeatedly true. Why would you NEED to get all of the backends working? As @mkborregaard stated, if you can get the PyPlot working, then the PyPlot backend works for Plots.jl, but you aren’t locked into the syntax of just PyPlot.

And I’m not saying that Plots.jl will do everything that PyPlot can do. There are a few features it hasn’t wrapped. But as always, if power users need some special feature, they can go directly to PyPlot and use it. My problem with this is that I am sitting here scratching my head because of how often there are questions from new users that are directly solved by “just use Plots.jl”. This question, the recent Reddit question about why everything (Gadfly) takes so long to startup, the repeated questions about adding dependencies to packages in order to plot (setting up recipes doesn’t add dependencies), changing themes (PlotThemes.jl already will do this on any backend), getting plotting to work on clusters, creating animations, and doing a bunch of advanced statistical plotting (for which there are already recipes for).

These questions come up all to often from users using Gadfly and PyPlot, and these are all solved problems by Plots.jl. I just cannot agree that new users should be recommended other libraries after how many times the easiest solution to their problem is just to use Plots.jl: they should have just started there.

This is getting off topic though, so we should probably take this to another thread if we want to continue. (I was planning on doing a blog post soon about this, so I am sure that would spark conversion)

1 Like

The thread went off topic because instead of discussing the actual problem you proposed a workaround (i.e. to drop PyPlot.jl and use Plots.jl) I would like to hear the opinion of @stevengj: Is the the official answer to issues with PyPlot.jl: Just use Plots.jl?

(this is not to blame Plots.jl, which is a very nice project. I just don’t understand why PyPlot.jl should not recommended anymore)

Chris, please be informed, that noone tries to take Plots.jl away from you (or others), but it seems to be a strong personal focus of you to propose the usage of Plots.jl even if it’s questionable that it provides a solution to the mentioned problem. Regarding the reddit discussion: It was you to claim Gadfly is slow and i don’t see a reply from the OP that your proposal has solved his workflow problem.

1 Like