JuliaPy / PyPlot.jl

Plotting for Julia based on matplotlib.pyplot
https://github.com/JuliaPy/PyPlot.jl
MIT License
478 stars 88 forks source link

using PyPlot fails #332

Closed algorithmx closed 6 years ago

algorithmx commented 6 years ago

Installed as instructed


Machine info XXX@XXX:~$ julia () | A fresh approach to technical computing () | () () | Documentation: https://docs.julialang.org | |_ | Type "?help" for help. | | | | | | |/ ` | | | | || | | | (| | | Version 0.6.1 (2017-10-24 22:15 UTC) / |_'|||_'_| | Official http://julialang.org/ release |/ | x86_64-pc-linux-gnu


First I opened the IJulia notebook $ using IJulia $ IJulia.notebook() then in the notebook I type $ using PyPlot and get the following error:


InitError: PyError (ccall(@pysym(:PyImport_ImportModule), PyPtr, (Cstring,), name)

The Python package matplotlib.pyplot could not be found by pyimport. Usually this means that you did not install matplotlib.pyplot in the Python version being used by PyCall.

PyCall is currently configured to use the Julia-specific Python distribution installed by the Conda.jl package. To install the matplotlib.pyplot module, you can use pyimport_conda("matplotlib.pyplot", PKG), where PKG is the Anaconda package the contains the module matplotlib.pyplot, or alternatively you can use the Conda package directly (via using Conda followed by Conda.add etcetera).

Alternatively, if you want to use a different Python distribution on your system, such as a system-wide Python (as opposed to the Julia-specific Python), you can re-configure PyCall with that Python. As explained in the PyCall documentation, set ENV["PYTHON"] to the path/name of the python executable you want to use, run Pkg.build("PyCall"), and re-launch Julia.

) <type 'exceptions.ImportError'> ImportError("/lib/x86_64-linux-gnu/libz.so.1: version `ZLIB_1.2.9' not found (required by /home/yunlong/.julia/v0.6/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/../../.././libpng16.so.16)",) File "/home/yunlong/.julia/v0.6/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/pyplot.py", line 29, in import matplotlib.colorbar File "/home/yunlong/.julia/v0.6/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/colorbar.py", line 36, in import matplotlib.contour as contour File "/home/yunlong/.julia/v0.6/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/contour.py", line 21, in import matplotlib.font_manager as font_manager File "/home/yunlong/.julia/v0.6/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/font_manager.py", line 58, in from matplotlib import afm, cbook, ft2font, rcParams, get_cachedir

during initialization of module PyPlot

Stacktrace: [1] pyerr_check at /home/yunlong/.julia/v0.6/PyCall/src/exception.jl:56 [inlined] [2] pyerr_check at /home/yunlong/.julia/v0.6/PyCall/src/exception.jl:61 [inlined] [3] macro expansion at /home/yunlong/.julia/v0.6/PyCall/src/exception.jl:81 [inlined] [4] pyimport(::String) at /home/yunlong/.julia/v0.6/PyCall/src/PyCall.jl:374 [5] init() at /home/yunlong/.julia/v0.6/PyPlot/src/init.jl:184 [6] _include_from_serialized(::String) at ./loading.jl:157 [7] _require_from_serialized(::Int64, ::Symbol, ::String, ::Bool) at ./loading.jl:200 [8] _require_search_from_serialized(::Int64, ::Symbol, ::String, ::Bool) at ./loading.jl:236 [9] _require(::Symbol) at ./loading.jl:441 [10] require(::Symbol) at ./loading.jl:405 [11] include_string(::String, ::String) at ./loading.jl:522

BoundaryValueProblems commented 6 years ago

I had exactly the same problem using the python under ~/.julia/v0.6/Conda/deps/usr/bin, which is the default. In the previous version, e.g., v0.5.2, it worked without any tweak. Now, the only way I can use PyPlot is to rebuild PyPlot using the system wide version of python, e.g., /usr/bin/X11/python as:

ENV["PYTHON"]="/usr/bin/X11/python"
Pkg.build("PyPlot")

Note however that before doing so, make sure that you installed matplotlib using the system wide python on a terminal:

$ python -mpip install -U pip
$ python -mpip install -U matplotlib

See the details at https://matplotlib.org/users/installing.html All these are quite cumbersome. I truly hope that we do not have to do this!! I had to do the above on my Linux machines and Windows machines. Somehow, I didn't have to do the same for my MacBook...

algorithmx commented 6 years ago

If the documentation instructs a user to install following certain procedures, such instructions should work without any tweaks.

BoundaryValueProblems commented 6 years ago

Actually, I have to correct my posting. Using the system wide python worked on my Windows machine and my 32bit Linux machine, but not on my 64bit Linux machine at this point. On the latter machine, after installing and building everything with the system wide python, I got the following error with PyPlot. Note that I didn't have any problem with PyCall. For example, I could run Pkg.test("PyCall") without any error. So the problem is in PyPlot:

using PyPlot
signal (11): Segmentation fault
while loading no file, in expression starting on line 0
unknown function (ip: 0x7f2fb8736d7f)
pyexists at /homes/xxx/.julia/v0.6/PyCall/src/gui.jl:11
pygui_works at /homes/xxx/.julia/v0.6/PyCall/src/gui.jl:22
unknown function (ip: 0x7f2fab40cfe2)
jl_call_fptr_internal at /buildworker/worker/package_linux64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /buildworker/worker/package_linux64/build/src/julia_internal.h:358 [inlined]
jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:41
find_backend at /homes/xxx/.julia/v0.6/PyPlot/src/init.jl:125
__init__ at /homes/xxx/.julia/v0.6/PyPlot/src/init.jl:190
unknown function (ip: 0x7f2fc1696bbf)
jl_call_fptr_internal at /buildworker/worker/package_linux64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /buildworker/worker/package_linux64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:1926
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1424 [inlined]
jl_module_run_initializer at /buildworker/worker/package_linux64/build/src/toplevel.c:87
jl_init_restored_modules at /buildworker/worker/package_linux64/build/src/dump.c:2443 [inlined]
_jl_restore_incremental at /buildworker/worker/package_linux64/build/src/dump.c:3317
jl_restore_incremental at /buildworker/worker/package_linux64/build/src/dump.c:3337
_include_from_serialized at ./loading.jl:157
_require_from_serialized at ./loading.jl:200
_require at ./loading.jl:464
require at ./loading.jl:405
unknown function (ip: 0x7f2fc1684bd2)
jl_call_fptr_internal at /buildworker/worker/package_linux64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /buildworker/worker/package_linux64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:1926
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1424 [inlined]
eval_import_path_ at /buildworker/worker/package_linux64/build/src/toplevel.c:403
eval_import_path at /buildworker/worker/package_linux64/build/src/toplevel.c:430 [inlined]
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:495
jl_toplevel_eval_in at /buildworker/worker/package_linux64/build/src/builtins.c:496
eval at ./boot.jl:235
unknown function (ip: 0x7f2fd5dfcacf)
jl_call_fptr_internal at /buildworker/worker/package_linux64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /buildworker/worker/package_linux64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:1926
eval_user_input at ./REPL.jl:66
unknown function (ip: 0x7f2fd5e7df8f)
jl_call_fptr_internal at /buildworker/worker/package_linux64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /buildworker/worker/package_linux64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:1926
macro expansion at ./REPL.jl:97 [inlined]
#1 at ./event.jl:73
unknown function (ip: 0x7f2fc15a434f)
jl_call_fptr_internal at /buildworker/worker/package_linux64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /buildworker/worker/package_linux64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:1926
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1424 [inlined]
start_task at /buildworker/worker/package_linux64/build/src/task.c:267
unknown function (ip: 0xffffffffffffffff)
Allocations: 18941911 (Pool: 18933117; Big: 8794); GC: 46
Segmentation fault (core dumped)

Yes, @algorithmx I agree with you. In principle, we do not have to do all these. But I just wanted to use PyPlot now.

stevengj commented 6 years ago

This is a duplicate of #151. See that issue for workarounds.

(The basic issue is that Julia and Matplotlib are linked to incompatible versions of zlib.)

BoundaryValueProblems commented 6 years ago

@stevengj I don't think the method suggested at #151 works for me. I followed the method suggested by @zekeriyasari on my linux machine. First of all the line: ln -s -f /usr/local/lib/libz.so.1.2.9/lib libz.so.1 should be perhaps ln -s -f /usr/local/lib/libz.so.1.2.9 libz.so.1 But, it's too dangerous to replace /lib/x86_64-linux-gnu/libz.so.1. It works for a while, but then I cannot even login to my machine since many programs depend on libz.so.1. We need another solution.

stevengj commented 6 years ago

I agree that another solution would be better, but please discuss at 151, not here.