JuliaPy / PyPlot.jl

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

numpy.core.multiarray failed to import (matplotlib cannot be found?) #450

Closed briochemc closed 5 years ago

briochemc commented 5 years ago

I get this error that suggests that matplotlib cannot be found although I am pretty sure it has been there the whole time :) I tried removing PyPlot and PyCall, re-adding them, and building PyCall after setting ENV["PYTHON"] = "" so that PyCall would be looking for the Python in .julia/conda, but without success. The error output (FYI everything ]uped, too):

julia> using PyPlot
[ Info: Recompiling stale cache file /Users/benoitpasquier/.julia/compiled/v1.1/PyPlot/oatAj.ji for PyPlot [d330b81b-6aea-500a-939a-2ce795aea3ee]
ImportError: numpy.core.multiarray failed to import
[ Info: Installing matplotlib via the Conda matplotlib package...
[ Info: Running `conda install -y matplotlib` in root environment
Collecting package metadata (current_repodata.json): done
Solving environment: done

# All requested packages already installed.

ImportError: numpy.core.multiarray failed to import
ERROR: InitError: PyError (PyImport_ImportModule

The Python package matplotlib could not be found by pyimport. Usually this means
that you did not install matplotlib 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 module, you can
use `pyimport_conda("matplotlib", PKG)`, where PKG is the Anaconda
package the contains the module matplotlib, 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.

) <class 'ImportError'>
ImportError('numpy.core.multiarray failed to import')
  File "/Users/benoitpasquier/.julia/conda/3/lib/python3.7/site-packages/matplotlib/__init__.py", line 205, in <module>
    _check_versions()
  File "/Users/benoitpasquier/.julia/conda/3/lib/python3.7/site-packages/matplotlib/__init__.py", line 190, in _check_versions
    from . import ft2font

Stacktrace:
 [1] pyimport(::String) at /Users/benoitpasquier/.julia/packages/PyCall/ttONZ/src/PyCall.jl:544
 [2] pyimport_conda(::String, ::String, ::String) at /Users/benoitpasquier/.julia/packages/PyCall/ttONZ/src/PyCall.jl:708
 [3] pyimport_conda at /Users/benoitpasquier/.julia/packages/PyCall/ttONZ/src/PyCall.jl:701 [inlined]
 [4] __init__() at /Users/benoitpasquier/.julia/packages/PyPlot/cdCMF/src/init.jl:169
 [5] _include_from_serialized(::String, ::Array{Any,1}) at ./loading.jl:633
 [6] _require_from_serialized(::String) at ./loading.jl:684
 [7] _require(::Base.PkgId) at ./loading.jl:967
 [8] require(::Base.PkgId) at ./loading.jl:858
 [9] require(::Module, ::Symbol) at ./loading.jl:853
during initialization of module PyPlot

I have been using PyPlot for a bit now and it was working fine until I probably updated or changed something I shouldn't have (likely when trying to get widgets to work with Interact in Jupyter notebooks), and now I can't get PyPlot to work anymore... I'm very confused... Any help appreciated!

briochemc commented 5 years ago

I think the problem was I somehow corrupted PyCall's python installation, so nuking .julia/conda and rebuilding PyCall from scractch worked. Closing because I don't think this is an issue but rather more of a rare case of "I messed up my environment somehow". But in case this last-resort advice could be useful for others, here is what I did (could maybe go in the readme's troubleshooting?)

Remove PyCall's conda target entirely

$ rm -r .julia/conda

Then in julia remove it all and rebuild PyCall

(v1.1) pkg> rm PyPlot
(v1.1) pkg> rm Conda
(v1.1) pkg> rm PyCall
(v1.1) pkg> add PyCall
julia> ENV["PYTHON"] = ""
(v1.1) pkg> build PyCall
julia> exit()

Then restarting julia to use PyCall and PyPlot

(v1.1) pkg> add PyPlot
julia> using PyPlot, PyCall

and it should import matplotlib and work (hopefully).