# Backend or Zlib problem with PyPlot / Matplotlib

**URL:** <https://discourse.julialang.org/t/backend-or-zlib-problem-with-pyplot-matplotlib/2685>\
**Category:** General Usage\
**Created:** [March 15, 2017, 7:15pm UTC](https://discourse.julialang.org/t/backend-or-zlib-problem-with-pyplot-matplotlib/2685 "2017-03-15T19:15:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielc/32/220_2.png) [@danielc](https://discourse.julialang.org/u/danielc)\
**Post date:** [March 15, 2017, 7:15pm UTC](https://discourse.julialang.org/t/backend-or-zlib-problem-with-pyplot-matplotlib/2685/1 "2017-03-15T19:15:52Z")

</div>

Hello everyone,

I have a new workstation and I’m starting to setup Julia and packages. I installed Julia 0.5.1 but I’m having trouble with PyPlot. After a seemingly successful installation, I get an error about backends and ZLIB:

```julia
julia> using PyPlot
/astro/research/duc299/.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: InitError: PyError (:PyImport_ImportModule) <type 'exceptions.ImportError'>
ImportError("/lib64/libz.so.1: version `ZLIB_1.2.3.4' not found (required by /astro/research/duc299/.julia/v0.5/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/../../../libpng16.so.16)",)
  File "/astro/research/duc299/.julia/v0.5/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/pyplot.py", line 29, in <module>
    import matplotlib.colorbar
  File "/astro/research/duc299/.julia/v0.5/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/colorbar.py", line 36, in <module>
    import matplotlib.contour as contour
  File "/astro/research/duc299/.julia/v0.5/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/contour.py", line 23, in <module>
    import matplotlib.text as text
  File "/astro/research/duc299/.julia/v0.5/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/text.py", line 33, in <module>
    from matplotlib.backend_bases import RendererBase
  File "/astro/research/duc299/.julia/v0.5/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 63, in <module>
    import matplotlib.textpath as textpath
  File "/astro/research/duc299/.julia/v0.5/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/textpath.py", line 20, in <module>
    from matplotlib.mathtext import MathTextParser
  File "/astro/research/duc299/.julia/v0.5/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/mathtext.py", line 62, in <module>
    import matplotlib._png as _png

 in pyerr_check at /astro/research/duc299/.julia/v0.5/PyCall/src/exception.jl:56 [inlined]
 in pyerr_check at /astro/research/duc299/.julia/v0.5/PyCall/src/exception.jl:61 [inlined]
 in macro expansion at /astro/research/duc299/.julia/v0.5/PyCall/src/exception.jl:81 [inlined]
 in pyimport(::String) at /astro/research/duc299/.julia/v0.5/PyCall/src/PyCall.jl:392
 in __init__ () at /astro/research/duc299/.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
during initialization of module PyPlot

```

I should mention that this is a CentOS workstation, so it may have old versions of key libraries like ZLib. That said, i am optimistic that this problem is solvable because I can actually plot using the Python / Conda system installed by the PyPlot package:

```julia
$ cd ~/.julia/v0.5/Conda/deps/usr/bin
$ ./ipython  
Python 2.7.13 |Continuum Analytics, Inc.| (default, Dec 20 2016, 23:09:15) 
Type "copyright", "credits" or "license" for more information.

IPython 5.3.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.

In [1]: import matplotlib.pyplot as plt

In [2]: import numpy as np

In [3]: t = np.arange(0.0, 2.0, 0.01)

In [4]: s = 1 + np.sin(2*np.pi*t)

In [5]: plt.plot(t, s)
Out[5]: [<matplotlib.lines.Line2D at 0x7fdeac0cdf10>]

In [6]: plt.savefig("foo.png")

In [7]: plt.show()

```

The last line produces a GUI plot, and the second-last line successfully produces a PNG file (which requires the ZLIB library). So it looks like the Python and Matplotlib install actually work; and these are the Python and Matplotlib that the PyPlot package sees. So it seems like everything should work… but I’m stuck. I don’t know where to go from here. Does anybody have a suggestion?

Thanks for the help.

Cheers!  
Daniel.

---

<div class="post-metadata">

**Author:** ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)\
**Post date:** [March 16, 2017, 1:48am UTC](https://discourse.julialang.org/t/backend-or-zlib-problem-with-pyplot-matplotlib/2685/2 "2017-03-16T01:48:02Z")

</div>

As @stevengj mentioned in [a similar thread](https://discourse.julialang.org/t/no-working-gui-backend-found-for-matplotlib/2479)

> [@No working GUI backend found for matplotlib](https://discourse.julialang.org/t/no-working-gui-backend-found-for-matplotlib/2479/9):
>
> See [error loading ZLIB (wrong libz library being linked) · Issue #151 · JuliaPy/PyPlot.jl · GitHub](https://github.com/JuliaPy/PyPlot.jl/issues/151) … the problem is that it is finding the wrong libz.so library

The Zlib project makes a good effort at backwards compatibility (using version scripts, if anyone is interested) so it should be safe to force Julia to use a newer version. Does PyPlot work for you if you start Julia as follows?

```shell
LD_PRELOAD=${HOME}/.julia/v0.5/Conda/deps/usr/lib/libz.so julia

```

You can also try setting LD\_LIBRARY\_PATH to the Conda lib directory, but that exposes your Julia process to other crocodiles in the Python dependency swamp.

---

<div class="post-metadata">

**Author:** ![danielc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielc/32/220_2.png) [@danielc](https://discourse.julialang.org/u/danielc)\
**Post date:** [March 16, 2017, 6:41pm UTC](https://discourse.julialang.org/t/backend-or-zlib-problem-with-pyplot-matplotlib/2685/3 "2017-03-16T18:41:22Z")

</div>

That works!! Thank you so much!
