Backend or Zlib problem with PyPlot / Matplotlib

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> 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:

$ 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.

As @stevengj mentioned in a similar thread

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?

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.

1 Like

That works!! Thank you so much!