JuliaPy / PyPlot.jl

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

Cannot use on Windows/julia 1.0.2 #414

Closed crbinz closed 5 years ago

crbinz commented 5 years ago
julia> using PyPlot
[ Info: Installing matplotlib via the Conda matplotlib package...
[ Info: Running `conda install -y matplotlib` in root environment
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("cannot import name 'is_string_like'",)
  File "C:\Users\cbinz\.julia\conda\3\lib\site-packages\matplotlib\__init__.py", line 122, in <module>
    from matplotlib.cbook import is_string_like, mplDeprecation, dedent, get_label

Stacktrace:
 [1] pyimport(::String) at C:\Users\cbinz\.julia\packages\PyCall\0jMpb\src\PyCall.jl:486
 [2] macro expansion at .\logging.jl:307 [inlined]
 [3] pyimport_conda(::String, ::String, ::String) at C:\Users\cbinz\.julia\packages\PyCall\0jMpb\src\PyCall.jl:653
 [4] pyimport_conda at C:\Users\cbinz\.julia\packages\PyCall\0jMpb\src\PyCall.jl:649 [inlined]
 [5] __init__() at C:\Users\cbinz\.julia\packages\PyPlot\fZuOQ\src\init.jl:174
 [6] _include_from_serialized(::String, ::Array{Any,1}) at .\loading.jl:633
 [7] macro expansion at .\logging.jl:310 [inlined]
 [8] _require_search_from_serialized(::Base.PkgId, ::String) at .\loading.jl:704
 [9] _require(::Base.PkgId) at .\loading.jl:937
 [10] require(::Base.PkgId) at .\loading.jl:858
 [11] macro expansion at .\logging.jl:309 [inlined]
 [12] require(::Module, ::Symbol) at .\loading.jl:840
during initialization of module PyPlot

I try the suggestion to use Conda to install matplotlib, but it just gives the same message as above (# All requested packages already installed.). PyPlot v2.6.3 is installed.

tkf commented 5 years ago

So this is the informative part:

ImportError("cannot import name 'is_string_like'",)
  File "C:\Users\cbinz\.julia\conda\3\lib\site-packages\matplotlib\__init__.py", line 122, in <module>
    from matplotlib.cbook import is_string_like, mplDeprecation, dedent, get_label

is_string_like is deprecated at matplotlib 2.1 https://github.com/matplotlib/matplotlib/pull/8011 and (I guess) removed at 3.0.

The scenario I can imagine that this error can happen is that matplotlib 3.x is installed first and then it is downgraded to 2.x for some other packages while conda failed to cleanup Python's compile cache. (Although it's not clear why the old cache is not recompiled...)

I think you can check matplotlib version by Conda.version("matplotlib") which may give us some hint.

If it was about Python's unclean cache, maybe you can fix it by: Conda.rm("matplotlib"), remove (or move to somewhere else) C:\Users\cbinz\.julia\conda\3\lib\site-packages\matplotlib if it still exists, and then Conda.add("matplotlib").

crbinz commented 5 years ago

Conda.version("matplotlib") gave v2.0.0, by the way. Following the rest of your instructions to remove matplotlib fixed things for me, thank you.