JuliaPy / PyPlot.jl

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

PyPlot keeps trying to install matplotlib even if it's already installed (Windows 10) #461

Closed BoundaryValueProblems closed 4 years ago

BoundaryValueProblems commented 4 years ago

Hello.

I'm facing difficulty to use PyPlot on my windows 10 machine. The versions I'm using are: Julia v1.3.0; Conda v1.3.0; PyCall v1.91.2; PyPlot v2.8.2. I already installed the latest matlibplot via Conda.update(), and it's v3.1.1 now. Also, the python executable used by PyCall seems to be correctly specified:

julia> using PyCall
julia> PyCall.python
"C:\\Users\\xxx\\.julia\\conda\\3\\python.exe"

Then, I got the following errors. Essentially, PyPlot keeps trying to install matplotlib even though it was already installed. In fact, the warnings below say "All requested packages already installed." Yet, each time when I try to use PyPlot, this happens and I cannot use it on windows. It works under macOS though. I would greatly appreciate it if someone could tell me what to do. Thanks!

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: PyCall.PyError("PyImport_ImportModule\n\nThe Python package matplotlib could not be found by pyimport. Usually this means\nthat you did not install matplotlib in the Python version being used by PyCall.\n\nPyCall is currently configured to use the Julia-specific Python distribution\ninstalled by the Conda.jl package.  To install the matplotlib module, you can\nuse `pyimport_conda(\"matplotlib\", PKG)`, where PKG is the Anaconda\npackage the contains the module matplotlib, or alternatively you can use the\nConda package directly (via `using Conda` followed 
by `Conda.add` etcetera).\n\nAlternatively, if you want to use a different Python distribution on your\nsystem, such as a system-wide Python (as 
opposed to the Julia-specific Python),\nyou can re-configure PyCall with that Python.   As explained in the PyCall\ndocumentation, set ENV[\"PYTHON\"] to the path/name of the python executable\nyou want to use, run Pkg.build(\"PyCall\"), and re-launch Julia.\n\n", PyCall.PyObject(Ptr{PyCall.PyObject_struct} @0x000000006b8a4290), PyCall.PyObject(Ptr{PyCall.PyObject_struct} @0x0000000030ba39e8), PyCall.PyObject(Ptr{PyCall.PyObject_struct} @0x0000000030bae888))
Stacktrace:
 [1] pyimport(::String) at C:\Users\xxx\.julia\packages\PyCall\ttONZ\src\PyCall.jl:544
 [2] pyimport_conda(::String, ::String, ::String) at C:\Users\xxx\.julia\packages\PyCall\ttONZ\src\PyCall.jl:708
 [3] pyimport_conda at C:\Users\xxx\.julia\packages\PyCall\ttONZ\src\PyCall.jl:701 [inlined]
 [4] __init__() at C:\Users\xxx\.julia\packages\PyPlot\4wzW1\src\init.jl:179
 [5] _include_from_serialized(::String, ::Array{Any,1}) at .\loading.jl:692
 [6] _require_search_from_serialized(::Base.PkgId, ::String) at .\loading.jl:776
 [7] _require(::Base.PkgId) at .\loading.jl:1001
 [8] require(::Base.PkgId) at .\loading.jl:922
 [9] require(::Module, ::Symbol) at .\loading.jl:917
during initialization of module PyPlot
stevengj commented 4 years ago

What happens if you do

using PyCall
pyimport("matplotlib")

?

BoundaryValueProblems commented 4 years ago

@stevengj , here is the error I got by doing so. Thanks for your further help!

julia> pyimport("matplotlib")
ERROR: 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('\n\nIMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!\n\nImporting the numpy c-extensions failed.\n- Try uninstalling and reinstalling numpy.\n- If you have already done that, then:\n  1. Check that you expected to use Python3.6 from "C:\\Program Files\\Julia-1.3.0\\bin\\julia.exe",\n     and that you have no directories in your PATH or PYTHONPATH that can\n     interfere with the Python and numpy version "1.17.4" you\'re trying to use.\n  2. If (1) looks fine, you can open a new issue at\n     https://github.com/numpy/numpy/issues.  Please include details on:\n     - how you installed Python\n     - how you installed numpy\n     - your operating system\n     - whether or not you have multiple versions of Python installed\n     - if you built from source, your compiler versions and ideally a build log\n\n- If you\'re working with a numpy git repository, try `git clean -xdf`\n  (removes all files not under version control) and rebuild numpy.\n\nNote: this error has many possible causes, so please don\'t comment on\nan existing issue about this - open a new one instead.\n\nOriginal error was: DLL load failed: The specified module could not be found.\n',)
  File "C:\Users\xxx\.julia\conda\3\lib\site-packages\matplotlib\__init__.py", line 138, in <module>
    from . import cbook, rcsetup
  File "C:\Users\xxx\.julia\conda\3\lib\site-packages\matplotlib\cbook\__init__.py", line 31, in <module>
    import numpy as np
  File "C:\Users\xxx\.julia\conda\3\lib\site-packages\numpy\__init__.py", line 142, in <module>
    from . import core
  File "C:\Users\xxx\.julia\conda\3\lib\site-packages\numpy\core\__init__.py", line 47, in <module>
    raise ImportError(msg)

Stacktrace:
 [1] pyimport(::String) at C:\Users\xxx\.julia\packages\PyCall\ttONZ\src\PyCall.jl:544
 [2] top-level scope at none:0
BoundaryValueProblems commented 4 years ago

Is this an numpy issue? I tried pyimport("numpy") and got the same error messages. Yet, I already installed numpy v1.17.4 via Conda. So, I'm quite puzzled...

BoundaryValueProblems commented 4 years ago

@stevengj I resolved the problem now. I would appreciate it if you could take a look at my posting https://github.com/JuliaPy/PyCall.jl/issues/730. Somehow, if I update various python packages via Conda.update(), then all these troubles occur...

stevengj commented 4 years ago

Seems to be a PATH issue in PyCall (see JuliaPy/PyCall.jl#730), not due to PyPlot per se.