JuliaPy / PyPlot.jl

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

using PyPlot causes InitError #406

Closed milankl closed 4 years ago

milankl commented 5 years ago

I've build PyPlot against python version 3.6.4 that I usually use, via ENV["PYTHON"] = /home/... This python has matplotlib 3.0.0 installed and it works fine. Although building doesn't throw an error, using PyPlot throws

julia> using PyPlot
ERROR: InitError: PyCall.PyError("PyImport_ImportModule\n\nThe Python package matplotlib.pyplot couldnot be found by pyimport

if in the same REPL session I rebuild it, using PyPlot runs through only throwing the

WARNING: using PyPlot.plt in module Main conflicts with an existing identifier.
WARNING: using PyPlot.axes in module Main conflicts with an existing identifier.

warning. However, whenever I try to do something like, I get

julia> plot(randn(300))
ERROR: ArgumentError: haskey of NULL PyObject
Stacktrace:
 [1] haskey(::PyObject, ::String) at /home/kloewer/.julia/packages/PyCall/0jMpb/src/PyCall.jl:310
 [2] #plot#85(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Array{Float64,1}) at /home/kloewer/.julia/packages/PyPlot/fZuOQ/src/PyPlot.jl:176
 [3] plot(::Array{Float64,1}) at /home/kloewer/.julia/packages/PyPlot/fZuOQ/src/PyPlot.jl:176
 [4] top-level scope at none:0

Building PyCall with ENV["PYTHON"] = "" solves the problem, but I find it a bit redundant having two python environments that essentially fulfill the same purpose.

milankl commented 5 years ago

Oh I think this is essentially the same as #369

stevengj commented 5 years ago

Probably something is missing from your PYTHONPATH or similar that is preventing pyimport("matplotlib") from working in Julia.

tkf commented 5 years ago

if in the same REPL session I rebuild it

Also, make sure to reboot the julia REPL after you re-build anything depending on PyCall.