JuliaPy / PyPlot.jl

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

InitError on Julia 1.0.1 #394

Closed gideonsimpson closed 6 years ago

gideonsimpson commented 6 years ago

The following issue has shown up for me. I'm using MacOS 10.13.16.

julia> using Plots

julia> pyplot()
┌ Warning: No working GUI backend found for matplotlib
└ @ PyPlot ~/.julia/packages/PyPlot/fZuOQ/src/init.jl:160
ERROR: InitError: PyError (PyImport_ImportModule) <class 'StopIteration'>
StopIteration()
  File "/Users/guardian/.julia/packages/Conda/hsaaN/deps/usr/lib/python3.7/site-packages/matplotlib/pyplot.py", line 32, in <module>
    import matplotlib.colorbar
  File "/Users/guardian/.julia/packages/Conda/hsaaN/deps/usr/lib/python3.7/site-packages/matplotlib/colorbar.py", line 32, in <module>
    import matplotlib.contour as contour
  File "/Users/guardian/.julia/packages/Conda/hsaaN/deps/usr/lib/python3.7/site-packages/matplotlib/contour.py", line 18, in <module>
    import matplotlib.font_manager as font_manager
  File "/Users/guardian/.julia/packages/Conda/hsaaN/deps/usr/lib/python3.7/site-packages/matplotlib/font_manager.py", line 1363, in <module>
    _rebuild()
  File "/Users/guardian/.julia/packages/Conda/hsaaN/deps/usr/lib/python3.7/site-packages/matplotlib/font_manager.py", line 1344, in _rebuild
    fontManager = FontManager()
  File "/Users/guardian/.julia/packages/Conda/hsaaN/deps/usr/lib/python3.7/site-packages/matplotlib/font_manager.py", line 987, in __init__
    self.afmlist = createFontList(afmfiles, fontext='afm')
  File "/Users/guardian/.julia/packages/Conda/hsaaN/deps/usr/lib/python3.7/site-packages/matplotlib/font_manager.py", line 481, in createFontList
    font = afm.AFM(fh)
  File "/Users/guardian/.julia/packages/Conda/hsaaN/deps/usr/lib/python3.7/site-packages/matplotlib/afm.py", line 398, in __init__
    self._composite) = _parse_afm(fh)
  File "/Users/guardian/.julia/packages/Conda/hsaaN/deps/usr/lib/python3.7/site-packages/matplotlib/afm.py", line 383, in _parse_afm
    _sanity_check(fh)
  File "/Users/guardian/.julia/packages/Conda/hsaaN/deps/usr/lib/python3.7/site-packages/matplotlib/afm.py", line 91, in _sanity_check
    line = next(fh)

Stacktrace:
 [1] pyimport(::String) at /Users/guardian/.julia/packages/PyCall/rUul9/src/PyCall.jl:486
 [2] __init__() at /Users/guardian/.julia/packages/PyPlot/fZuOQ/src/init.jl:187
 [3] _include_from_serialized(::String, ::Array{Any,1}) at ./loading.jl:630
 [4] macro expansion at ./logging.jl:312 [inlined]
 [5] _require_search_from_serialized(::Base.PkgId, ::String) at ./loading.jl:701
 [6] _require(::Base.PkgId) at ./loading.jl:934
 [7] require(::Base.PkgId) at ./loading.jl:855
 [8] macro expansion at ./logging.jl:311 [inlined]
 [9] require(::Module, ::Symbol) at ./loading.jl:837
 [10] top-level scope at /Users/guardian/.julia/packages/Plots/UtVfv/src/backends.jl:389
 [11] eval at ./boot.jl:319 [inlined]
 [12] _initialize_backend(::Plots.PyPlotBackend) at /Users/guardian/.julia/packages/Plots/UtVfv/src/backends.jl:388
 [13] backend(::Plots.PyPlotBackend) at /Users/guardian/.julia/packages/Plots/UtVfv/src/backends.jl:196
 [14] backend(::Symbol) at /Users/guardian/.julia/packages/Plots/UtVfv/src/backends.jl:209
 [15] pyplot() at /Users/guardian/.julia/packages/Plots/UtVfv/src/backends.jl:29
 [16] top-level scope at none:0
during initialization of module PyPlot
tkf commented 6 years ago

What are the versions of the packages you are using? You can show us the output of:

using Pkg
Pkg.status(Pkg.PKGMODE_MANIFEST)  # or "]st"
using Conda
Conda.list()

Did you make sure that it worked in Python? You can check it by:

using PyCall
run(`$(PyCall.pyprogramname) -c "from matplotlib import pyplot; pyplot.plot([1, 2, 3]); pyplot.show()"`)
gideonsimpson commented 6 years ago

I think there are the relevant packages:

[8f4d0f93] Conda v1.0.2
[91a5bcdd] Plots v0.20.4
[d330b81b] PyPlot v2.6.3

and

conda                     4.5.11                   py37_0  
conda-env                 2.6.0                         1  
matplotlib                3.0.0            py37h54f8f79_0
numpy                     1.15.2           py37h6a91979_0  
numpy-base                1.15.2           py37h8a80b8c_0
python                    3.7.0                hc167b69_0

and the PyCall command returns:

Traceback (most recent call last):
  File "/Users/guardian/.julia/packages/Conda/hsaaN/deps/usr/lib/python3.7/site-packages/matplotlib/font_manager.py", line 1353, in <module>
    fontManager = json_load(_fmcache)
  File "/Users/guardian/.julia/packages/Conda/hsaaN/deps/usr/lib/python3.7/site-packages/matplotlib/font_manager.py", line 888, in json_load
    with open(filename, 'r') as fh:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/guardian/.matplotlib/fontlist-v300.json'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/guardian/.julia/packages/Conda/hsaaN/deps/usr/lib/python3.7/site-packages/matplotlib/pyplot.py", line 32, in <module>
    import matplotlib.colorbar
  File "/Users/guardian/.julia/packages/Conda/hsaaN/deps/usr/lib/python3.7/site-packages/matplotlib/colorbar.py", line 32, in <module>
    import matplotlib.contour as contour
  File "/Users/guardian/.julia/packages/Conda/hsaaN/deps/usr/lib/python3.7/site-packages/matplotlib/contour.py", line 18, in <module>
    import matplotlib.font_manager as font_manager
  File "/Users/guardian/.julia/packages/Conda/hsaaN/deps/usr/lib/python3.7/site-packages/matplotlib/font_manager.py", line 1363, in <module>
    _rebuild()
  File "/Users/guardian/.julia/packages/Conda/hsaaN/deps/usr/lib/python3.7/site-packages/matplotlib/font_manager.py", line 1344, in _rebuild
    fontManager = FontManager()
  File "/Users/guardian/.julia/packages/Conda/hsaaN/deps/usr/lib/python3.7/site-packages/matplotlib/font_manager.py", line 987, in __init__
    self.afmlist = createFontList(afmfiles, fontext='afm')
  File "/Users/guardian/.julia/packages/Conda/hsaaN/deps/usr/lib/python3.7/site-packages/matplotlib/font_manager.py", line 481, in createFontList
    font = afm.AFM(fh)
  File "/Users/guardian/.julia/packages/Conda/hsaaN/deps/usr/lib/python3.7/site-packages/matplotlib/afm.py", line 398, in __init__
    self._composite) = _parse_afm(fh)
  File "/Users/guardian/.julia/packages/Conda/hsaaN/deps/usr/lib/python3.7/site-packages/matplotlib/afm.py", line 383, in _parse_afm
    _sanity_check(fh)
  File "/Users/guardian/.julia/packages/Conda/hsaaN/deps/usr/lib/python3.7/site-packages/matplotlib/afm.py", line 91, in _sanity_check
    line = next(fh)
StopIteration
ERROR: failed process: Process(`/Users/guardian/.julia/packages/Conda/hsaaN/deps/usr/bin/python -c 'from matplotlib import pyplot; pyplot.plot([1, 2, 3]); pyplot.show()'`, ProcessExited(1)) [1]
Stacktrace:
 [1] error(::String, ::Base.Process, ::String, ::Int64, ::String) at ./error.jl:42
 [2] pipeline_error at ./process.jl:705 [inlined]
 [3] #run#504(::Bool, ::Function, ::Cmd) at ./process.jl:663
 [4] run(::Cmd) at ./process.jl:661
 [5] top-level scope at none:0
tkf commented 6 years ago

Yeah I thought it's matplotlib 3. Unless you can make the last command (it's pure Python, nothing to do with Julia or PyCall.jl) work, PyPlot.jl won't work. Something like Conda.add("matplotlib<3") to downgrade matplotlib may help. Otherwise you need to report the bug to matplotlib and/or Anaconda.

This may be relevant: https://github.com/matplotlib/matplotlib/issues/12291

gideonsimpson commented 6 years ago

Ok, downgrading it appears to work. I have no specific need for mpl 3.0.

tkf commented 6 years ago

Good that it works.