JuliaPy / PyPlot.jl

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

Setup error on pristine new system #340

Closed davidanthoff closed 6 years ago

davidanthoff commented 6 years ago

I have an essentially new Windows 10 system. Tried to install things with Pkg.add("PyCall"), and then just do using PyPlot, and get this error message:

   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: https://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.6.2 (2017-12-13 18:08 UTC)
 _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org/ release
|__/                   |  x86_64-w64-mingw32

julia> Pkg.add("PyPlot")
INFO: Cloning cache of LaTeXStrings from https://github.com/stevengj/LaTeXStrings.jl.git
INFO: Cloning cache of PyCall from https://github.com/JuliaPy/PyCall.jl.git
INFO: Cloning cache of PyPlot from https://github.com/JuliaPy/PyPlot.jl.git
INFO: Installing LaTeXStrings v0.3.0
INFO: Installing PyCall v1.15.0
INFO: Installing PyPlot v2.3.2
INFO: Building Conda
INFO: Building PyCall
INFO: Using the Python distribution in the Conda package by default.
To use a different Python version, set ENV["PYTHON"]="pythoncommand" and re-run Pkg.build("PyCall").
Solving environment: done

## Package Plan ##

  environment location: C:\Users\david\.julia\v0.6\Conda\deps\usr

  added / updated specs:
    - numpy

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    mkl-2018.0.1               |       h2108138_4       155.2 MB
    numpy-1.14.0               |   py27hfef472a_0         4.9 MB
    intel-openmp-2018.0.0      |       hd92c6cd_8         1.4 MB
    icc_rt-2017.0.4            |       h97af966_0         8.0 MB
    conda-4.4.7                |           py27_0         953 KB
    ------------------------------------------------------------
                                           Total:       170.4 MB

The following NEW packages will be INSTALLED:

    icc_rt:       2017.0.4-h97af966_0
    intel-openmp: 2018.0.0-hd92c6cd_8
    mkl:          2018.0.1-h2108138_4
    numpy:        1.14.0-py27hfef472a_0

The following packages will be UPDATED:

    conda:        4.4.6-py27_0          --> 4.4.7-py27_0

Downloading and Extracting Packages
mkl 2018.0.1: ############################################################################################################################################################################################## | 100%
numpy 1.14.0: ############################################################################################################################################################################################## | 100%
intel-openmp 2018.0.0: ##################################################################################################################################################################################### | 100%
icc_rt 2017.0.4: ########################################################################################################################################################################################### | 100%
conda 4.4.7: ############################################################################################################################################################################################### | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
INFO: PyCall is using C:\Users\david\.julia\v0.6\Conda\deps\usr\python.exe (Python 2.7.14) at C:\Users\david\.julia\v0.6\Conda\deps\usr\python.exe, libpython = C:\Users\david\.julia\v0.6\Conda\deps\usr\python27
INFO: C:\Users\david\.julia\v0.6\PyCall\deps\deps.jl has been updated
INFO: C:\Users\david\.julia\v0.6\PyCall\deps\PYTHON has been updated
INFO: Package database updated

julia> using PyCall
INFO: Precompiling module PyCall.

julia> PyCall.libpython
"C:\\Users\\david\\.julia\\v0.6\\Conda\\deps\\usr\\python27"

julia> using PyPlot
INFO: Precompiling module PyPlot.
INFO: Installing matplotlib via the Conda matplotlib package...
Solving environment: done

## Package Plan ##

  environment location: C:\Users\david\.julia\v0.6\Conda\deps\usr

  added / updated specs:
    - matplotlib

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    backports.functools_lru_cache-1.4|   py27h9586e20_1           9 KB
    freetype-2.8               |       hea645e0_1         462 KB
    pytz-2017.3                |   py27hca431c1_0         209 KB
    matplotlib-2.1.1           |   py27h3be7b3c_0         6.5 MB
    cycler-0.10.0              |   py27h59acbbf_0          13 KB
    pyparsing-2.2.0            |   py27hc7d9fa6_1          94 KB
    ------------------------------------------------------------
                                           Total:         7.3 MB

The following NEW packages will be INSTALLED:

    backports.functools_lru_cache: 1.4-py27h9586e20_1
    cycler:                        0.10.0-py27h59acbbf_0
    freetype:                      2.8-hea645e0_1
    matplotlib:                    2.1.1-py27h3be7b3c_0
    pyparsing:                     2.2.0-py27hc7d9fa6_1
    pytz:                          2017.3-py27hca431c1_0

Downloading and Extracting Packages
backports.functools_lru_cache 1.4: ######################################################################################################################################################################### | 100%
freetype 2.8: ############################################################################################################################################################################################## | 100%
pytz 2017.3: ############################################################################################################################################################################################### | 100%
matplotlib 2.1.1: ########################################################################################################################################################################################## | 100%
cycler 0.10.0: ############################################################################################################################################################################################# | 100%
pyparsing 2.2.0: ########################################################################################################################################################################################### | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
ERROR: InitError: PyError (ccall(@pysym(:PyImport_ImportModule), PyPtr, (Cstring,), name)

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

) <type 'exceptions.ImportError'>
ImportError('No module named mpl_toolkits.mplot3d',)

Stacktrace:
 [1] pyerr_check at C:\Users\david\.julia\v0.6\PyCall\src\exception.jl:56 [inlined]
 [2] pyerr_check at C:\Users\david\.julia\v0.6\PyCall\src\exception.jl:61 [inlined]
 [3] macro expansion at C:\Users\david\.julia\v0.6\PyCall\src\exception.jl:81 [inlined]
 [4] pyimport(::String) at C:\Users\david\.julia\v0.6\PyCall\src\PyCall.jl:374
 [5] __init__() at C:\Users\david\.julia\v0.6\PyPlot\src\init.jl:205
 [6] _include_from_serialized(::String) at .\loading.jl:157
 [7] _require_from_serialized(::Int64, ::Symbol, ::String, ::Bool) at .\loading.jl:200
 [8] _require(::Symbol) at .\loading.jl:498
 [9] require(::Symbol) at .\loading.jl:405
during initialization of module PyPlot

julia> quit()
davidanthoff commented 6 years ago

After some further disucssions on slack, it seems quite widely known that the current latest released version of PyPlot v2.3.2 simply doesn't work on Windows and that one needs to pin to v2.3.1 to get a working version. Maybe there could be a bug fix release v2.3.3 that simply undoes whatever was introduced in v2.3.2?

davidanthoff commented 6 years ago

Although, looking at the diff between v2.3.1 and v2.3.2 it seems unlikely that those changes would explain the error... I wish I had just restarted julia when v2.3.2 was still installed and tried to load it again...

Here is how I continued from the log above: I exited julia, then started it again, pinned PyCall to v2.3.1. Then I was able to load it. I then restarted julia again, then freed PyCall so it went back to v2.3.2 and now I can lead that version just fine as well.

So maybe this is something where things just don't work at the first attempt to load the package, but subsequent attempts might work. Can't reproduce that anymore now, but that seems a possible explanation.

stevengj commented 6 years ago

I just ran into this today. See my explanation here.

The issue is that, apparently because of a library conflict, Anaconda no longer installs mplot3d with matplotlib. A workaround is to do Conda.add("basemap"), which will downgrade numpy in order to install mplot3d. But I'm planning to patch PyPlot shortly so that it works (albeit without 3d plots) if mplot3d is not present.

davidanthoff commented 6 years ago

Ah, thanks. Agreed on the plan, that seems like a good short term patch.

daschw commented 6 years ago

Do we have to adjust the Plots pyplot backend now (e.g. here https://github.com/JuliaPlots/Plots.jl/blob/master/src/backends/pyplot.jl#L86)?

stevengj commented 6 years ago

@daschw, yes, it would be good to fix Plots as well.

It doesn't look like you use your mplot3d constant at all, so you can just delete that. And you can just replace your pyart3d constant with PyPlot.art3D (this works even on previous PyPlot versions, so no need to bump your dependencies).

daschw commented 6 years ago

Great, thanks for the info!