JuliaPy / PyPlot.jl

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

Failure to import matplotlib #456

Closed qua4tre closed 5 years ago

qua4tre commented 5 years ago

This recently began to happen after I uninstalled an old Anaconda distribution and installed Anaconda3 (although I don't know if that's related or not). AFAICT, PyCall is using a private Miniconda installation, not the Anaconda distribution I just installed. However, even when I set ENV["PYTHON"] = "C:/Users/musikat/AppData/Local/Continuum/anaconda3/python.exe" and ]build PyCall, I get the same ImportError after using PyPlot; the only thing that changes is the intervening message about matplotlib not being found by pyimport. Any help would be appreciated.

I am using Julia 1.1.1 on Windows 10.

julia> using PyPlot
[ 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.

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('DLL load failed: The specified module could not be found.',)
  File "C:\Users\musikat\.julia\conda\3\lib\site-packages\matplotlib\__init__.py", line 138, in <module>
    from . import cbook, rcsetup
  File "C:\Users\musikat\.julia\conda\3\lib\site-packages\matplotlib\cbook\__init__.py", line 31, in <module>
    import numpy as np
  File "C:\Users\musikat\.julia\conda\3\lib\site-packages\numpy\__init__.py", line 140, in <module>
    from . import _distributor_init
  File "C:\Users\musikat\.julia\conda\3\lib\site-packages\numpy\_distributor_init.py", line 34, in <module>
    from . import _mklinit

Stacktrace:
 [1] pyimport(::String) at C:\Users\musikat\.julia\packages\PyCall\ttONZ\src\PyCall.jl:544
 [2] pyimport_conda(::String, ::String, ::String) at C:\Users\musikat\.julia\packages\PyCall\ttONZ\src\PyCall.jl:708
 [3] pyimport_conda at C:\Users\musikat\.julia\packages\PyCall\ttONZ\src\PyCall.jl:701 [inlined]
 [4] __init__() at C:\Users\musikat\.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
PaulSoderlind commented 5 years ago

At some point, I noticed that letting the Anaconda installer change the system path (Win 10) helped. (Maybe you didn't select this option when upgrading?) As of now, the first folders in my path are

C:\Miniconda3
C:\Miniconda3\Library\mingw-w64\bin
C:\Miniconda3\Library\usr\bin
C:\Miniconda3\Library\bin
C:\Miniconda3\Scripts

(since I installed to C:\Miniconda3)

qua4tre commented 5 years ago

You're right. Checking the box "Add Anaconda to my PATH environment variable" during installation, against Anaconda's current recommendation, fixes it. Thank you!

stevengj commented 5 years ago

Maybe you need to use a python.exe in C:\Miniconda3\Library\mingw-w64\bin or one of the other paths?