# Pyplot in Julia PyError

**URL:** <https://discourse.julialang.org/t/pyplot-in-julia-pyerror/115310>\
**Category:** New to Julia\
**Tags:** pyplot\
**Created:** [June 7, 2024, 6:58am UTC](https://discourse.julialang.org/t/pyplot-in-julia-pyerror/115310 "2024-06-07T06:58:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sihyun\_Kim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sihyun_kim/32/207216_2.png) [@Sihyun\_Kim](https://discourse.julialang.org/u/Sihyun_Kim)\
**Post date:** [June 7, 2024, 6:58am UTC](https://discourse.julialang.org/t/pyplot-in-julia-pyerror/115310/1 "2024-06-07T06:58:09Z")

</div>

Python and matplotlib are installed in anaconda 3. I am trying to import it to julia. I type in repl:

```julia
using PyPlot

```

Then It shows the following message:

```julia
[ Info: Installing matplotlib via the Conda matplotlib package...
[ Info: Running `conda install -y matplotlib` in root environment
Channels:
 - defaults
 - conda-forge
Platform: win-64
Collecting package metadata (repodata.json): done
Solving environment: done

==> WARNING: A newer version of conda exists. <==
    current version: 24.3.0
    latest version: 24.5.0

Please update conda by running

    $ conda update -n base -c conda-forge conda

# All requested packages already installed.

ERROR: 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 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 that 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('DLL load failed while importing _imaging: The specified module could not be found.')
  File "C:\Users\Sihyun\.julia\conda\3\x86_64\lib\site-packages\matplotlib\ __init__.py", line 161, in <module>
    from . import _api, _version, cbook, _docstring, rcsetup
  File "C:\Users\Sihyun\.julia\conda\3\x86_64\lib\site-packages\matplotlib\rcsetup.py", line 27, in <module>
    from matplotlib.colors import Colormap, is_color_like
  File "C:\Users\Sihyun\.julia\conda\3\x86_64\lib\site-packages\matplotlib\colors.py", line 52, in <module>
    from PIL import Image
  File "C:\Users\Sihyun\.julia\conda\3\x86_64\lib\site-packages\PIL\Image.py", line 88, in <module>
    from . import _imaging as core

Stacktrace:
  [1] pyimport(name::String)
    @ PyCall C:\Users\Sihyun\.julia\packages\PyCall\1gn3u\src\PyCall.jl:558
  [2] pyimport_conda
    @ C:\Users\Sihyun\.julia\packages\PyCall\1gn3u\src\PyCall.jl:722
  [3] pyimport_conda
    @ C:\Users\Sihyun\.julia\packages\PyCall\1gn3u\src\PyCall.jl:715 [inlined]
  [4] __init__ ()
    @ PyPlot C:\Users\Sihyun\.julia\packages\PyPlot\2MlrT\src\init.jl:174
  [5] run_module_init(mod::Module, i::Int64)
    @ Base .\loading.jl:1134
  [6] register_restored_modules(sv::Core.SimpleVector, pkg::Base.PkgId, path::String)
    @ Base .\loading.jl:1122
  [7] _include_from_serialized(pkg::Base.PkgId, path::String, ocachepath::String, depmods::Vector{Any})
    @ Base .\loading.jl:1067
  [8] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String, build_id::UInt128)
    @ Base .\loading.jl:1581
  [9] _require(pkg::Base.PkgId, env::String)
    @ Base .\loading.jl:1938
 [10] __require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base .\loading.jl:1812
 [11] #invoke_in_world#3
    @ .\essentials.jl:926 [inlined]
 [12] invoke_in_world
    @ .\essentials.jl:923 [inlined]
 [13] _require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base .\loading.jl:1803
 [14] macro expansion
    @ .\loading.jl:1790 [inlined]
 [15] macro expansion
    @ .\lock.jl:267 [inlined]
 [16] __require(into::Module, mod::Symbol)
    @ Base .\loading.jl:1753
 [17] #invoke_in_world#3
    @ .\essentials.jl:926 [inlined]
 [18] invoke_in_world
    @ .\essentials.jl:923 [inlined]
 [19] require(into::Module, mod::Symbol)
    @ Base .\loading.jl:1746
during initialization of module PyPlot

caused by: 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 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 that 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('DLL load failed while importing _imaging: The specified module could not be found.')
  File "C:\Users\Sihyun\.julia\conda\3\x86_64\lib\site-packages\matplotlib\ __init__.py", line 161, in <module>
    from . import _api, _version, cbook, _docstring, rcsetup
  File "C:\Users\Sihyun\.julia\conda\3\x86_64\lib\site-packages\matplotlib\rcsetup.py", line 27, in <module>
    from matplotlib.colors import Colormap, is_color_like
  File "C:\Users\Sihyun\.julia\conda\3\x86_64\lib\site-packages\matplotlib\colors.py", line 52, in <module>
    from PIL import Image
  File "C:\Users\Sihyun\.julia\conda\3\x86_64\lib\site-packages\PIL\Image.py", line 88, in <module>
    from . import _imaging as core

Stacktrace:
  [1] pyimport(name::String)
    @ PyCall C:\Users\Sihyun\.julia\packages\PyCall\1gn3u\src\PyCall.jl:558
  [2] pyimport_conda
    @ C:\Users\Sihyun\.julia\packages\PyCall\1gn3u\src\PyCall.jl:716
  [3] pyimport_conda
    @ C:\Users\Sihyun\.julia\packages\PyCall\1gn3u\src\PyCall.jl:715 [inlined]
  [4] __init__ ()
    @ PyPlot C:\Users\Sihyun\.julia\packages\PyPlot\2MlrT\src\init.jl:174
  [5] run_module_init(mod::Module, i::Int64)
    @ Base .\loading.jl:1134
  [6] register_restored_modules(sv::Core.SimpleVector, pkg::Base.PkgId, path::String)
    @ Base .\loading.jl:1122
  [7] _include_from_serialized(pkg::Base.PkgId, path::String, ocachepath::String, depmods::Vector{Any})
    @ Base .\loading.jl:1067
  [8] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String, build_id::UInt128)
    @ Base .\loading.jl:1581
  [9] _require(pkg::Base.PkgId, env::String)
    @ Base .\loading.jl:1938
 [10] __require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base .\loading.jl:1812
 [11] #invoke_in_world#3
    @ .\essentials.jl:926 [inlined]
 [12] invoke_in_world
    @ .\essentials.jl:923 [inlined]
 [13] _require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base .\loading.jl:1803
 [14] macro expansion
    @ .\loading.jl:1790 [inlined]
 [15] macro expansion
    @ .\lock.jl:267 [inlined]
 [16] __require(into::Module, mod::Symbol)
    @ Base .\loading.jl:1753
 [17] #invoke_in_world#3
    @ .\essentials.jl:926 [inlined]
 [18] invoke_in_world
    @ .\essentials.jl:923 [inlined]
 [19] require(into::Module, mod::Symbol)
    @ Base .\loading.jl:1746

```

How can i solve this issue?

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [June 7, 2024, 7:21am UTC](https://discourse.julialang.org/t/pyplot-in-julia-pyerror/115310/2 "2024-06-07T07:21:39Z")

</div>

Either you execute the suggested command:

```julia
conda update -n base -c conda-forge conda

```

to update conda, or you do nothing.

This is just a warning, not an error, you can safely ignore it.

---

<div class="post-metadata">

**Author:** ![Sihyun\_Kim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sihyun_kim/32/207216_2.png) [@Sihyun\_Kim](https://discourse.julialang.org/u/Sihyun_Kim)\
**Post date:** [June 7, 2024, 7:43am UTC](https://discourse.julialang.org/t/pyplot-in-julia-pyerror/115310/3 "2024-06-07T07:43:51Z")

</div>

the problem is “matplotlib” is not imported with this error.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [June 7, 2024, 7:47am UTC](https://discourse.julialang.org/t/pyplot-in-julia-pyerror/115310/4 "2024-06-07T07:47:48Z")

</div>

Well, you did not share the error message.

You can always do:

```julia
using Pkg
Pkg.add("PyCall")
ENV["PYTHON"]=""
Pkg.build("PyCall")

```

Reading the installation instructions might help: [GitHub - JuliaPy/PyPlot.jl: Plotting for Julia based on matplotlib.pyplot](https://github.com/JuliaPy/PyPlot.jl)

---

<div class="post-metadata">

**Author:** ![Sihyun\_Kim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sihyun_kim/32/207216_2.png) [@Sihyun\_Kim](https://discourse.julialang.org/u/Sihyun_Kim)\
**Post date:** [June 7, 2024, 8:01am UTC](https://discourse.julialang.org/t/pyplot-in-julia-pyerror/115310/5 "2024-06-07T08:01:57Z")

</div>

After your code, I type

> using PyPlot

it gives the same error. (Please scroll down it)

```julia
julia> using PyPlot
[ Info: Installing matplotlib via the Conda matplotlib package...
[ Info: Running `conda install -y matplotlib` in root environment
Channels:
 - defaults
 - conda-forge
Platform: win-64
Collecting package metadata (repodata.json): done
Solving environment: done

==> WARNING: A newer version of conda exists. <==
    current version: 24.3.0
    latest version: 24.5.0

Please update conda by running

    $ conda update -n base -c conda-forge conda

# All requested packages already installed.

ERROR: 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 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 that 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('DLL load failed while importing _imaging: The specified module could not be found.')
  File "C:\Users\Sihyun\.julia\conda\3\x86_64\lib\site-packages\matplotlib\ __init__.py", line 161, in <module>
    from . import _api, _version, cbook, _docstring, rcsetup
  File "C:\Users\Sihyun\.julia\conda\3\x86_64\lib\site-packages\matplotlib\rcsetup.py", line 27, in <module>
    from matplotlib.colors import Colormap, is_color_like
  File "C:\Users\Sihyun\.julia\conda\3\x86_64\lib\site-packages\matplotlib\colors.py", line 52, in <module>
    from PIL import Image
  File "C:\Users\Sihyun\.julia\conda\3\x86_64\lib\site-packages\PIL\Image.py", line 88, in <module>
    from . import _imaging as core

Stacktrace:
  [1] pyimport(name::String)
    @ PyCall C:\Users\Sihyun\.julia\packages\PyCall\1gn3u\src\PyCall.jl:558
  [2] pyimport_conda
    @ C:\Users\Sihyun\.julia\packages\PyCall\1gn3u\src\PyCall.jl:722
  [3] pyimport_conda
    @ C:\Users\Sihyun\.julia\packages\PyCall\1gn3u\src\PyCall.jl:715 [inlined]
  [4] __init__ ()
    @ PyPlot C:\Users\Sihyun\.julia\packages\PyPlot\2MlrT\src\init.jl:174
  [5] run_module_init(mod::Module, i::Int64)
    @ Base .\loading.jl:1134
  [6] register_restored_modules(sv::Core.SimpleVector, pkg::Base.PkgId, path::String)
    @ Base .\loading.jl:1122
  [7] _include_from_serialized(pkg::Base.PkgId, path::String, ocachepath::String, depmods::Vector{Any})
    @ Base .\loading.jl:1067
  [8] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String, build_id::UInt128)
    @ Base .\loading.jl:1581
  [9] _require(pkg::Base.PkgId, env::String)
    @ Base .\loading.jl:1938
 [10] __require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base .\loading.jl:1812
 [11] #invoke_in_world#3
    @ .\essentials.jl:926 [inlined]
 [12] invoke_in_world
    @ .\essentials.jl:923 [inlined]
 [13] _require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base .\loading.jl:1803
 [14] macro expansion
    @ .\loading.jl:1790 [inlined]
 [15] macro expansion
    @ .\lock.jl:267 [inlined]
 [16] __require(into::Module, mod::Symbol)
    @ Base .\loading.jl:1753
 [17] #invoke_in_world#3
    @ .\essentials.jl:926 [inlined]
 [18] invoke_in_world
    @ .\essentials.jl:923 [inlined]
 [19] require(into::Module, mod::Symbol)
    @ Base .\loading.jl:1746
during initialization of module PyPlot

caused by: 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 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 that 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('DLL load failed while importing _imaging: The specified module could not be found.')
  File "C:\Users\Sihyun\.julia\conda\3\x86_64\lib\site-packages\matplotlib\ __init__.py", line 161, in <module>
    from . import _api, _version, cbook, _docstring, rcsetup
  File "C:\Users\Sihyun\.julia\conda\3\x86_64\lib\site-packages\matplotlib\rcsetup.py", line 27, in <module>
    from matplotlib.colors import Colormap, is_color_like
  File "C:\Users\Sihyun\.julia\conda\3\x86_64\lib\site-packages\matplotlib\colors.py", line 52, in <module>
    from PIL import Image
  File "C:\Users\Sihyun\.julia\conda\3\x86_64\lib\site-packages\PIL\Image.py", line 88, in <module>
    from . import _imaging as core

Stacktrace:
  [1] pyimport(name::String)
    @ PyCall C:\Users\Sihyun\.julia\packages\PyCall\1gn3u\src\PyCall.jl:558
  [2] pyimport_conda
    @ C:\Users\Sihyun\.julia\packages\PyCall\1gn3u\src\PyCall.jl:716
  [3] pyimport_conda
    @ C:\Users\Sihyun\.julia\packages\PyCall\1gn3u\src\PyCall.jl:715 [inlined]
  [4] __init__ ()
    @ PyPlot C:\Users\Sihyun\.julia\packages\PyPlot\2MlrT\src\init.jl:174
  [5] run_module_init(mod::Module, i::Int64)
    @ Base .\loading.jl:1134
  [6] register_restored_modules(sv::Core.SimpleVector, pkg::Base.PkgId, path::String)
    @ Base .\loading.jl:1122
  [7] _include_from_serialized(pkg::Base.PkgId, path::String, ocachepath::String, depmods::Vector{Any})
    @ Base .\loading.jl:1067
  [8] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String, build_id::UInt128)
    @ Base .\loading.jl:1581
  [9] _require(pkg::Base.PkgId, env::String)
    @ Base .\loading.jl:1938
 [10] __require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base .\loading.jl:1812
 [11] #invoke_in_world#3
    @ .\essentials.jl:926 [inlined]
 [12] invoke_in_world
    @ .\essentials.jl:923 [inlined]
 [13] _require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base .\loading.jl:1803
 [14] macro expansion
    @ .\loading.jl:1790 [inlined]
 [15] macro expansion
    @ .\lock.jl:267 [inlined]
 [16] __require(into::Module, mod::Symbol)
    @ Base .\loading.jl:1753
 [17] #invoke_in_world#3
    @ .\essentials.jl:926 [inlined]
 [18] invoke_in_world
    @ .\essentials.jl:923 [inlined]
 [19] require(into::Module, mod::Symbol)
    @ Base .\loading.jl:1746

```

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [June 7, 2024, 8:31am UTC](https://discourse.julialang.org/t/pyplot-in-julia-pyerror/115310/6 "2024-06-07T08:31:52Z")

</div>

Sorry that I did not scroll down first, thanks to pointing that out.

This is a strange error indeed.

Can someone else look at this issue who has more knowledge about Conda?

Otherwise, please create a bug report at [Issues · JuliaPy/PyPlot.jl · GitHub](https://github.com/JuliaPy/PyPlot.jl/issues) or try [GitHub - JuliaPy/PythonPlot.jl: Plotting for Julia based on matplotlib.pyplot](https://github.com/JuliaPy/PythonPlot.jl)

---

<div class="post-metadata">

**Author:** ![alkoedl](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@alkoedl](https://discourse.julialang.org/u/alkoedl)\
**Post date:** [June 7, 2024, 7:54pm UTC](https://discourse.julialang.org/t/pyplot-in-julia-pyerror/115310/7 "2024-06-07T19:54:53Z")

</div>

Looks like the error I encountered here: [Fresh Julia/PyPlot install errors with \_imaging: the specified module could not be found](https://discourse.julialang.org/t/fresh-julia-pyplot-install-errors-with-imaging-the-specified-module-could-not-be-found/109311).  
Installing PyPlot seems broken currently.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [June 7, 2024, 8:33pm UTC](https://discourse.julialang.org/t/pyplot-in-julia-pyerror/115310/8 "2024-06-07T20:33:59Z")

</div>

> [@alkoedl](#):
>
> Installing PyPlot seems broken currently.

Well, it works fine on Linux, and when I last tested it on Windows 10 two weeks ago it also worked fine. If it doesn’t work for you, please create a bug report.
