Skip to content

ModuleNotFoundError("No module named 'matplotlib'") #521

@rafaqz

Description

@rafaqz

Loading PyPlot.jl with pyplot() from plots is giving this error, on both Ubuntu and Macos with Julia v1.6.

PyPlot version is 2.9.0. It seems to precompile ok but errors, I think on pyplot():

Edit: Ok I just realised that ENV["PYTHON"]="" is required. The problem is this is all in a Manifest.toml file... so we need to add that line before instantiate. Has there been any thought to swapping this behaviour?

ERROR: LoadError: InitError: PyError (PyImport_ImportModule

The Python package matplotlib could not be imported 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 Python version at:

/usr/bin/python3

and you should use whatever mechanism you usually use (apt-get, pip, conda,
etcetera) to install the Python package containing the matplotlib module.

One alternative is to re-configure PyCall to use a different Python
version on your system: set ENV["PYTHON"] to the path/name of the python
executable you want to use, run Pkg.build("PyCall"), and re-launch Julia.

Another alternative is to configure PyCall to use a Julia-specific Python
distribution via the Conda.jl package (which installs a private Anaconda
Python distribution), which has the advantage that packages can be installed
and kept up-to-date via Julia.  As explained in the PyCall documentation,
set ENV["PYTHON"]="", run Pkg.build("PyCall"), and re-launch Julia. Then,
To install the matplotlib module, you can use `pyimport_conda("matplotlib", PKG)`,
where PKG is the Anaconda package that contains the module matplotlib,
or alternatively you can use the Conda package directly (via
`using Conda` followed by `Conda.add` etcetera).

) <class 'ModuleNotFoundError'>
ModuleNotFoundError("No module named 'matplotlib'")

Stacktrace:
  [1] pyimport(name::String)
    @ PyCall ~/.julia/packages/PyCall/tqyST/src/PyCall.jl:547
  [2] pyimport_conda(modulename::String, condapkg::String, channel::String)
    @ PyCall ~/.julia/packages/PyCall/tqyST/src/PyCall.jl:705
  [3] pyimport_conda
    @ ~/.julia/packages/PyCall/tqyST/src/PyCall.jl:704 [inlined]
  [4] __init__()
    @ PyPlot ~/.julia/packages/PyPlot/XHEG0/src/init.jl:179
  [5] _include_from_serialized(path::String, depmods::Vector{Any})
    @ Base ./loading.jl:674
  [6] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String)
    @ Base ./loading.jl:760
  [7] _require(pkg::Base.PkgId)
    @ Base ./loading.jl:998
  [8] require(uuidkey::Base.PkgId)
    @ Base ./loading.jl:914
  [9] require(into::Module, mod::Symbol)
    @ Base ./loading.jl:901
 [10] top-level scope
    @ ~/.julia/packages/Plots/YicDu/src/backends.jl:505
 [11] eval
    @ ./boot.jl:360 [inlined]
 [12] _initialize_backend(#unused#::Plots.PyPlotBackend)
    @ Plots ~/.julia/packages/Plots/YicDu/src/backends.jl:504
 [13] backend
    @ ~/.julia/packages/Plots/YicDu/src/backends.jl:174 [inlined]
 [14] pyplot(; kw::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Plots ~/.julia/packages/Plots/YicDu/src/backends.jl:31
 [15] pyplot()
    @ Plots ~/.julia/packages/Plots/YicDu/src/backends.jl:31
 [16] top-level scope
    @ ~/work/SpatialMechanisticModellingInJulia/SpatialMechanisticModellingInJulia/src/plots.jl:3
 [17] include(fname::String)
    @ Base.MainInclude ./client.jl:444
 [18] top-level scope
    @ none:1
during initialization of module PyPlot

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions