After a long time with a perfectly well working PyPlot I today had to install Julia and PyPlot from scratch on a new computer. Adding PyPlot and building Conda/PyCall works. Upon “using PyPlot” conda/matplotlib are installed. However, the process errors after the installation with
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.10.0 (2023-12-25)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
(@v1.10) pkg> st
Installing known registries into `C:\Users\alk\.julia`
Status `C:\Users\alk\.julia\environments\v1.10\Project.toml` (empty project)
(@v1.10) pkg> add PyPlot
Updating registry at `C:\Users\alk\.julia\registries\General.toml`
Resolving package versions...
Installed Parsers ─────────── v2.8.1
Installed ColorTypes ──────── v0.11.4
Installed Conda ───────────── v1.10.0
Installed FixedPointNumbers ─ v0.8.4
Installed JSON ────────────── v0.21.4
Installed PyCall ──────────── v1.96.4
Installed PrecompileTools ─── v1.2.0
Installed Preferences ─────── v1.4.1
Installed VersionParsing ──── v1.3.0
Installed PyPlot ──────────── v2.11.2
Installed LaTeXStrings ────── v1.3.1
Installed Reexport ────────── v1.2.2
Installed MacroTools ──────── v0.5.13
Installed Colors ──────────── v0.12.10
Updating `C:\Users\alk\.julia\environments\v1.10\Project.toml`
[d330b81b] + PyPlot v2.11.2
Updating `C:\Users\alk\.julia\environments\v1.10\Manifest.toml`
[3da002f7] + ColorTypes v0.11.4
[5ae59095] + Colors v0.12.10
[8f4d0f93] + Conda v1.10.0
[53c48c17] + FixedPointNumbers v0.8.4
[682c06a0] + JSON v0.21.4
[b964fa9f] + LaTeXStrings v1.3.1
[1914dd2f] + MacroTools v0.5.13
[69de0a69] + Parsers v2.8.1
[aea7be01] + PrecompileTools v1.2.0
[21216c6a] + Preferences v1.4.1
[438e738f] + PyCall v1.96.4
[d330b81b] + PyPlot v2.11.2
[189a3867] + Reexport v1.2.2
[81def892] + VersionParsing v1.3.0
[0dad84c5] + ArgTools v1.1.1
[56f22d72] + Artifacts
[2a0f44e3] + Base64
[ade2ca70] + Dates
[f43a241f] + Downloads v1.6.0
[7b1f6079] + FileWatching
[b27032c2] + LibCURL v0.6.4
[37e2e46d] + LinearAlgebra
[56ddb016] + Logging
[d6f4376e] + Markdown
[a63ad114] + Mmap
[ca575930] + NetworkOptions v1.2.0
[de0858da] + Printf
[9a3f8284] + Random
[ea8e919c] + SHA v0.7.0
[9e88b42a] + Serialization
[6462fe0b] + Sockets
[2f01184e] + SparseArrays v1.10.0
[10745b16] + Statistics v1.10.0
[fa267f1f] + TOML v1.0.3
[8dfed614] + Test
[cf7118a7] + UUIDs
[4ec0a83e] + Unicode
[e66e0078] + CompilerSupportLibraries_jll v1.0.5+1
[deac9b47] + LibCURL_jll v8.4.0+0
[29816b5a] + LibSSH2_jll v1.11.0+1
[c8ffd9c3] + MbedTLS_jll v2.28.2+1
[14a3606d] + MozillaCACerts_jll v2023.1.10
[4536629a] + OpenBLAS_jll v0.3.23+2
[bea87d4a] + SuiteSparse_jll v7.2.1+1
[83775a58] + Zlib_jll v1.2.13+1
[8e850b90] + libblastrampoline_jll v5.8.0+1
[8e850ede] + nghttp2_jll v1.52.0+1
Building Conda ─→ `C:\Users\alk\.julia\scratchspaces\44cfe95a-1eb2-52ea-b672-e2afdf69b78f\51cab8e982c5b598eea9c8ceaced4b58d9dd37c9\build.log`
Building PyCall → `C:\Users\alk\.julia\scratchspaces\44cfe95a-1eb2-52ea-b672-e2afdf69b78f\9816a3826b0ebf49ab4926e2b18842ad8b5c8f04\build.log`
Precompiling project...
16 dependencies successfully precompiled in 35 seconds. 4 already precompiled.
(@v1.10) pkg> st
Status `C:\Users\alk\.julia\environments\v1.10\Project.toml`
[d330b81b] PyPlot v2.11.2
julia> using PyPlot
[ Info: Installing matplotlib via the Conda matplotlib package...
[ Info: Running `conda install -y matplotlib` in root environment
Channels:
- anaconda-fusion
- defaults
- conda-forge
Platform: win-64
Collecting package metadata (repodata.json): done
Solving environment: done
## Package Plan ##
environment location: C:\Users\alk\.julia\conda\3\x86_64
added / updated specs:
- matplotlib
The following packages will be downloaded:
package | build
---------------------------|-----------------
brotli-1.0.9 | ha925a31_2 332 KB
contourpy-1.2.0 | py310h59b6b97_0 203 KB
cycler-0.11.0 | pyhd3eb1b0_0 12 KB
fonttools-4.25.0 | pyhd3eb1b0_0 632 KB
freetype-2.12.1 | ha860e81_0 490 KB
giflib-5.2.1 | h8cc25b3_3 88 KB
glib-2.69.1 | h5dc1a3c_2 1.8 MB
gst-plugins-base-1.18.5 | h9e645db_0 1.7 MB
gstreamer-1.18.5 | hd78058f_0 1.7 MB
icu-58.2 | ha925a31_3 9.4 MB
jpeg-9e | h2bbff1b_1 320 KB
kiwisolver-1.4.4 | py310hd77b12b_0 60 KB
lerc-3.0 | hd77b12b_0 120 KB
libclang-12.0.0 |default_h627e005_2 17.8 MB
libdeflate-1.17 | h2bbff1b_1 153 KB
libogg-1.3.5 | h2bbff1b_1 33 KB
libpng-1.6.39 | h8cc25b3_0 369 KB
libtiff-4.5.0 | h8a3f274_0 1.2 MB
libvorbis-1.3.7 | he774522_0 202 KB
libwebp-1.3.2 | hbc33d0d_0 73 KB
libwebp-base-1.3.2 | h2bbff1b_0 306 KB
matplotlib-3.8.0 | py310haa95532_0 9 KB
matplotlib-base-3.8.0 | py310h4ed8f06_0 6.8 MB
munkres-1.1.4 | py_0 13 KB
openjpeg-2.4.0 | h4fc8c34_0 219 KB
pcre-8.45 | hd77b12b_0 382 KB
pillow-10.0.1 | py310h045eedc_0 788 KB
ply-3.11 | py310haa95532_0 81 KB
pyparsing-3.0.9 | py310haa95532_0 154 KB
pyqt-5.15.10 | py310hd77b12b_0 4.1 MB
pyqt5-sip-12.13.0 | py310h2bbff1b_0 75 KB
python-dateutil-2.8.2 | pyhd3eb1b0_0 233 KB
qt-main-5.15.2 | he8e5bd7_7 50.0 MB
sip-6.7.12 | py310hd77b12b_0 521 KB
six-1.16.0 | pyhd3eb1b0_1 18 KB
sqlite-3.41.2 | h2bbff1b_0 894 KB
tomli-2.0.1 | py310haa95532_0 25 KB
tornado-6.3.3 | py310h2bbff1b_0 647 KB
zlib-1.2.13 | hcfcfb64_5 105 KB conda-forge
------------------------------------------------------------
Total: 101.7 MB
The following NEW packages will be INSTALLED:
brotli pkgs/main/win-64::brotli-1.0.9-ha925a31_2
contourpy pkgs/main/win-64::contourpy-1.2.0-py310h59b6b97_0
cycler pkgs/main/noarch::cycler-0.11.0-pyhd3eb1b0_0
fonttools pkgs/main/noarch::fonttools-4.25.0-pyhd3eb1b0_0
freetype pkgs/main/win-64::freetype-2.12.1-ha860e81_0
giflib pkgs/main/win-64::giflib-5.2.1-h8cc25b3_3
glib pkgs/main/win-64::glib-2.69.1-h5dc1a3c_2
gst-plugins-base pkgs/main/win-64::gst-plugins-base-1.18.5-h9e645db_0
gstreamer pkgs/main/win-64::gstreamer-1.18.5-hd78058f_0
icu pkgs/main/win-64::icu-58.2-ha925a31_3
jpeg pkgs/main/win-64::jpeg-9e-h2bbff1b_1
kiwisolver pkgs/main/win-64::kiwisolver-1.4.4-py310hd77b12b_0
lerc pkgs/main/win-64::lerc-3.0-hd77b12b_0
libclang pkgs/main/win-64::libclang-12.0.0-default_h627e005_2
libdeflate pkgs/main/win-64::libdeflate-1.17-h2bbff1b_1
libogg pkgs/main/win-64::libogg-1.3.5-h2bbff1b_1
libpng pkgs/main/win-64::libpng-1.6.39-h8cc25b3_0
libtiff pkgs/main/win-64::libtiff-4.5.0-h8a3f274_0
libvorbis pkgs/main/win-64::libvorbis-1.3.7-he774522_0
libwebp pkgs/main/win-64::libwebp-1.3.2-hbc33d0d_0
libwebp-base pkgs/main/win-64::libwebp-base-1.3.2-h2bbff1b_0
matplotlib pkgs/main/win-64::matplotlib-3.8.0-py310haa95532_0
matplotlib-base pkgs/main/win-64::matplotlib-base-3.8.0-py310h4ed8f06_0
munkres pkgs/main/noarch::munkres-1.1.4-py_0
openjpeg pkgs/main/win-64::openjpeg-2.4.0-h4fc8c34_0
pcre pkgs/main/win-64::pcre-8.45-hd77b12b_0
pillow pkgs/main/win-64::pillow-10.0.1-py310h045eedc_0
ply pkgs/main/win-64::ply-3.11-py310haa95532_0
pyparsing pkgs/main/win-64::pyparsing-3.0.9-py310haa95532_0
pyqt pkgs/main/win-64::pyqt-5.15.10-py310hd77b12b_0
pyqt5-sip pkgs/main/win-64::pyqt5-sip-12.13.0-py310h2bbff1b_0
python-dateutil pkgs/main/noarch::python-dateutil-2.8.2-pyhd3eb1b0_0
qt-main pkgs/main/win-64::qt-main-5.15.2-he8e5bd7_7
sip pkgs/main/win-64::sip-6.7.12-py310hd77b12b_0
six pkgs/main/noarch::six-1.16.0-pyhd3eb1b0_1
sqlite pkgs/main/win-64::sqlite-3.41.2-h2bbff1b_0
tomli pkgs/main/win-64::tomli-2.0.1-py310haa95532_0
tornado pkgs/main/win-64::tornado-6.3.3-py310h2bbff1b_0
zlib conda-forge/win-64::zlib-1.2.13-hcfcfb64_5
Downloading and Extracting Packages:
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
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\alk\.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\alk\.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\alk\.julia\conda\3\x86_64\lib\site-packages\matplotlib\colors.py", line 52, in <module>
from PIL import Image
File "C:\Users\alk\.julia\conda\3\x86_64\lib\site-packages\PIL\Image.py", line 82, in <module>
from . import _imaging as core
Stacktrace:
[1] pyimport(name::String)
@ PyCall C:\Users\alk\.julia\packages\PyCall\1gn3u\src\PyCall.jl:558
[2] pyimport_conda
@ C:\Users\alk\.julia\packages\PyCall\1gn3u\src\PyCall.jl:722
[3] pyimport_conda
@ PyCall C:\Users\alk\.julia\packages\PyCall\1gn3u\src\PyCall.jl:715 [inlined]
[4] __init__()
@ PyPlot C:\Users\alk\.julia\packages\PyPlot\2MlrT\src\init.jl:174
[5] run_module_init(mod::Module, i::Int64)
@ Base .\loading.jl:1128
[6] register_restored_modules(sv::Core.SimpleVector, pkg::Base.PkgId, path::String)
@ Base .\loading.jl:1116
[7] _include_from_serialized(pkg::Base.PkgId, path::String, ocachepath::String, depmods::Vector{Any})
@ Base .\loading.jl:1061
[8] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String, build_id::UInt128)
@ Base .\loading.jl:1575
[9] _require(pkg::Base.PkgId, env::String)
@ Base .\loading.jl:1932
[10] __require_prelocked(uuidkey::Base.PkgId, env::String)
@ Base .\loading.jl:1806
[11] #invoke_in_world#3
@ Base .\essentials.jl:921 [inlined]
[12] invoke_in_world
@ Base .\essentials.jl:918 [inlined]
[13] _require_prelocked(uuidkey::Base.PkgId, env::String)
@ Base .\loading.jl:1797
[14] macro expansion
@ Base .\loading.jl:1784 [inlined]
[15] macro expansion
@ Base .\lock.jl:267 [inlined]
[16] __require(into::Module, mod::Symbol)
@ Base .\loading.jl:1747
[17] #invoke_in_world#3
@ Base .\essentials.jl:921 [inlined]
[18] invoke_in_world
@ Base .\essentials.jl:918 [inlined]
[19] require(into::Module, mod::Symbol)
@ Base .\loading.jl:1740
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 'ModuleNotFoundError'>
ModuleNotFoundError("No module named 'matplotlib'")
Stacktrace:
[1] pyimport(name::String)
@ PyCall C:\Users\alk\.julia\packages\PyCall\1gn3u\src\PyCall.jl:558
[2] pyimport_conda
@ C:\Users\alk\.julia\packages\PyCall\1gn3u\src\PyCall.jl:716
[3] pyimport_conda
@ PyCall C:\Users\alk\.julia\packages\PyCall\1gn3u\src\PyCall.jl:715 [inlined]
[4] __init__()
@ PyPlot C:\Users\alk\.julia\packages\PyPlot\2MlrT\src\init.jl:174
[5] run_module_init(mod::Module, i::Int64)
@ Base .\loading.jl:1128
[6] register_restored_modules(sv::Core.SimpleVector, pkg::Base.PkgId, path::String)
@ Base .\loading.jl:1116
[7] _include_from_serialized(pkg::Base.PkgId, path::String, ocachepath::String, depmods::Vector{Any})
@ Base .\loading.jl:1061
[8] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String, build_id::UInt128)
@ Base .\loading.jl:1575
[9] _require(pkg::Base.PkgId, env::String)
@ Base .\loading.jl:1932
[10] __require_prelocked(uuidkey::Base.PkgId, env::String)
@ Base .\loading.jl:1806
[11] #invoke_in_world#3
@ Base .\essentials.jl:921 [inlined]
[12] invoke_in_world
@ Base .\essentials.jl:918 [inlined]
[13] _require_prelocked(uuidkey::Base.PkgId, env::String)
@ Base .\loading.jl:1797
[14] macro expansion
@ Base .\loading.jl:1784 [inlined]
[15] macro expansion
@ Base .\lock.jl:267 [inlined]
[16] __require(into::Module, mod::Symbol)
@ Base .\loading.jl:1747
[17] #invoke_in_world#3
@ Base .\essentials.jl:921 [inlined]
[18] invoke_in_world
@ Base .\essentials.jl:918 [inlined]
[19] require(into::Module, mod::Symbol)
@ Base .\loading.jl:1740
julia>
So, the actual error seems to be that _imaging cannot be found. Checking the respective directory gives me
C:\Users\alk\.julia\conda\3\x86_64\Lib\site-packages\PIL
__pycache__
__init__.py
__main__.py
_binary.py
_deprecate.py
_imaging.cp310-win_amd64.pyd
_imagingft.cp310-win_amd64.pyd
_imagingmath.cp310-win_amd64.pyd
_imagingmorph.cp310-win_amd64.pyd
_imagingtk.cp310-win_amd64.pyd
_tkinter_finder.py
_util.py
_version.py
...
So, there is at least “_imaging.cp310-win_amd64.pyd” is there.
This install is on a new computer running Windows 11 Enterprise. I tried installing Julia in my home directory as well as globally with admin privilages. Same result. The environment is empty before adding PyPlot. I tried installing in the global environment as well as in a temporary environment. Same result.
Interestingly, a different computer (also running Windows 11 Enterprise) that has exactly the same versions of Julia and PyPlot (1.10.0 and 2.11.2) runs PyPlot without problems. However, this installation was not done from scratch, but through upgrades with a long history. I noticed that conda seems to have a different version on the two computers:
on the working one: conda-23.3.1-py3.10.egg-info
on the failing one: conda-23.11.0.dist-info
could this be a problem?
On both computers I’m using Julia’s internal conda/Python installation. The computers do not have an additional external Python.
Any ideas?