PyPlot.jl
PyPlot.jl copied to clipboard
Pyplot crash on window
A short PyPlot program is crashing on my Windows 11 machine (i.e., the Julia REPL exits with no error message). I verified that it works correctly on Linux. This is Julia 1.9.3, PyPlot 2.11.2. The data file br1copy.txt [br1copy.txt](https://github.com/JuliaPy/PyPlot.jl/files/13823984/br1copy.txt)
is attached.
module readbr1
using PyPlot
function readbr(filename, stepnum)
ststepnum = string(stepnum)
it = zeros(Int,0)
res1 = zeros(0)
res2 = zeros(0)
open(filename, "r") do h
while true
p = readline(h)
s = split(p)
if length(s) < 12 || s[1] != "step" || s[3] != ststepnum
if eof(h)
break
else
continue
end
end
itnum = parse(Int,s[6])
push!(it, itnum)
#println(itnum)
push!(res1, parse(Float64, s[9]))
push!(res2, parse(Float64, s[12]))
if eof(h)
break
end
end
end
return it, res1, res2
end
function makeplots(it, res1, res2)
figure(1)
clf()
semilogy(it, res1)
figure(2)
clf()
semilogy(it, res2)
nothing
end
it, res1, res2 = readbr("br1copy.txt", 6)
makeplots(it, res1, res2)
end
This issue occurs on a particular Windows machine but not others, so it may be difficult to reproduce.
On the same Windows 11 box I created a new user test_julia
, downloaded Julia 1.10.0 from scratch, installed PyPlot from scratch, and encountered the a crash as soon as I typed figure(1)
. There were a few warnings during the PyPlot installation and build (see below), but none of them appear serious.
Microsoft Windows [Version 10.0.22621.2861]
(c) Microsoft Corporation. All rights reserved.
C:\Users\test_julia>winget install julia -s msstore
The `msstore` source requires that you view the following agreements before using.
Terms of Transaction: https://aka.ms/microsoft-store-terms-of-transaction
The source requires the current machine's 2-letter geographic region to be sent to the backend service to function properly (ex. "US").
Do you agree to all the source agreements terms?
[Y] Yes [N] No: y
Found Julia [9NJNWW8PVKMN] Version Unknown
This package is provided through Microsoft Store. winget may need to acquire the package from Microsoft Store on behalf of the current user.
Agreements for Julia [9NJNWW8PVKMN] Version Unknown
Version: Unknown
Publisher: Julia Computing, Inc.
Publisher Url: https://julialang.org/
Description: Julia is a high-level, high-performance, dynamic, open-source programming language.
License: ms-windows-store://pdp/?ProductId=9NJNWW8PVKMN
Privacy Url: https://juliacomputing.com/privacy/
Agreements:
Category: Developer tools
C:\Users\test_julia>julia
Installing Julia 1.10.0+0.x64.w64.mingw32
_
_ _ _(_)_ | 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> add PyPlot
Installing known registries into `C:\Users\test_julia\.julia`
Updating registry at `C:\Users\test_julia\.julia\registries\General.toml`
Resolving package versions...
Installed PrecompileTools ─── v1.2.0
Installed Conda ───────────── v1.10.0
Installed FixedPointNumbers ─ v0.8.4
Installed VersionParsing ──── v1.3.0
Installed Parsers ─────────── v2.8.1
Installed ColorTypes ──────── v0.11.4
Installed Preferences ─────── v1.4.1
Installed PyCall ──────────── v1.96.4
Installed PyPlot ──────────── v2.11.2
Installed LaTeXStrings ────── v1.3.1
Installed MacroTools ──────── v0.5.12
Installed Colors ──────────── v0.12.10
Installed JSON ────────────── v0.21.4
Installed Reexport ────────── v1.2.2
Updating `C:\Users\test_julia\.julia\environments\v1.10\Project.toml`
[d330b81b] + PyPlot v2.11.2
Updating `C:\Users\test_julia\.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.12
[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\test_julia\.julia\scratchspaces\44cfe95a-1eb2-52ea-b672-e2afdf69b78f\51cab8e982c5b598eea9c8ceaced4b58d9dd37c9\build.log`
Building PyCall → `C:\Users\test_julia\.julia\scratchspaces\44cfe95a-1eb2-52ea-b672-e2afdf69b78f\9816a3826b0ebf49ab4926e2b18842ad8b5c8f04\build.log`
Precompiling project...
16 dependencies successfully precompiled in 18 seconds. 4 already precompiled.
julia> using PyPlot
[ Info: Installing matplotlib via the Conda matplotlib package...
[ Info: Running `conda install -y matplotlib` in root environment
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: done
==> WARNING: A newer version of conda exists. <==
current version: 23.3.1
latest version: 23.11.0
Please update conda by running
$ conda update -n base -c conda-forge conda
Or to minimize the number of packages updated during conda update use
conda install conda=23.11.0
## Package Plan ##
environment location: C:\Users\test_julia\.julia\conda\3\x86_64
added / updated specs:
- matplotlib
The following packages will be downloaded:
package | build
---------------------------|-----------------
brotli-1.1.0 | hcfcfb64_1 19 KB conda-forge
brotli-bin-1.1.0 | hcfcfb64_1 20 KB conda-forge
contourpy-1.2.0 | py310h232114e_0 186 KB conda-forge
cycler-0.12.1 | pyhd8ed1ab_0 13 KB conda-forge
fonttools-4.47.0 | py310h8d17308_0 1.8 MB conda-forge
freetype-2.12.1 | hdaf720e_2 498 KB conda-forge
gettext-0.21.1 | h5728263_0 5.3 MB conda-forge
glib-2.78.3 | h12be248_0 495 KB conda-forge
glib-tools-2.78.3 | h12be248_0 141 KB conda-forge
gst-plugins-base-1.22.8 | h001b923_1 2.0 MB conda-forge
gstreamer-1.22.8 | hb4038d2_1 1.8 MB conda-forge
icu-73.2 | h63175ca_0 12.8 MB conda-forge
kiwisolver-1.4.5 | py310h232114e_1 54 KB conda-forge
lcms2-2.16 | h67d730c_0 496 KB conda-forge
lerc-4.0.0 | h63175ca_0 190 KB conda-forge
libbrotlicommon-1.1.0 | hcfcfb64_1 69 KB conda-forge
libbrotlidec-1.1.0 | hcfcfb64_1 32 KB conda-forge
libbrotlienc-1.1.0 | hcfcfb64_1 241 KB conda-forge
libclang-15.0.7 |default_h77d9078_3 144 KB conda-forge
libclang13-15.0.7 |default_h77d9078_3 20.9 MB conda-forge
libdeflate-1.19 | hcfcfb64_0 150 KB conda-forge
libglib-2.78.3 | h16e383f_0 2.5 MB conda-forge
libjpeg-turbo-3.0.0 | hcfcfb64_1 804 KB conda-forge
libogg-1.3.4 | h8ffe710_1 34 KB conda-forge
libpng-1.6.39 | h19919ed_0 336 KB conda-forge
libtiff-4.6.0 | h6e2ebb7_2 769 KB conda-forge
libvorbis-1.3.7 | h0e60522_0 267 KB conda-forge
libwebp-base-1.3.2 | hcfcfb64_0 263 KB conda-forge
libxcb-1.15 | hcd874cb_0 947 KB conda-forge
m2w64-gcc-libgfortran-5.3.0| 6 342 KB conda-forge
m2w64-gcc-libs-5.3.0 | 7 520 KB conda-forge
m2w64-gcc-libs-core-5.3.0 | 7 214 KB conda-forge
m2w64-gmp-6.1.0 | 2 726 KB conda-forge
m2w64-libwinpthread-git-5.0.0.4634.697f757| 2 31 KB conda-forge
matplotlib-3.8.2 | py310h5588dad_0 9 KB conda-forge
matplotlib-base-3.8.2 | py310hc9baf74_0 6.6 MB conda-forge
msys2-conda-epoch-20160418 | 1 3 KB conda-forge
munkres-1.1.4 | pyh9f0ad1d_0 12 KB conda-forge
openjpeg-2.5.0 | h3d672ee_3 231 KB conda-forge
pcre2-10.42 | h17e33f8_0 860 KB conda-forge
pillow-10.2.0 | py310h1e6a543_0 39.6 MB conda-forge
ply-3.11 | py_1 44 KB conda-forge
pthread-stubs-0.4 | hcd874cb_1001 6 KB conda-forge
pyparsing-3.1.1 | pyhd8ed1ab_0 87 KB conda-forge
pyqt-5.15.9 | py310h1fd54f2_5 3.7 MB conda-forge
pyqt5-sip-12.12.2 | py310h00ffb61_5 78 KB conda-forge
python-dateutil-2.8.2 | pyhd8ed1ab_0 240 KB conda-forge
qt-main-5.15.8 | h9e85ed6_18 58.0 MB conda-forge
sip-6.7.12 | py310h00ffb61_0 493 KB conda-forge
six-1.16.0 | pyh6c4a22f_0 14 KB conda-forge
toml-0.10.2 | pyhd8ed1ab_0 18 KB conda-forge
tomli-2.0.1 | pyhd8ed1ab_0 16 KB conda-forge
tornado-6.3.3 | py310h8d17308_1 630 KB conda-forge
unicodedata2-15.1.0 | py310h8d17308_0 361 KB conda-forge
xorg-libxau-1.0.11 | hcd874cb_0 50 KB conda-forge
xorg-libxdmcp-1.1.3 | hcd874cb_0 66 KB conda-forge
------------------------------------------------------------
Total: 166.0 MB
The following NEW packages will be INSTALLED:
brotli conda-forge/win-64::brotli-1.1.0-hcfcfb64_1
brotli-bin conda-forge/win-64::brotli-bin-1.1.0-hcfcfb64_1
contourpy conda-forge/win-64::contourpy-1.2.0-py310h232114e_0
cycler conda-forge/noarch::cycler-0.12.1-pyhd8ed1ab_0
fonttools conda-forge/win-64::fonttools-4.47.0-py310h8d17308_0
freetype conda-forge/win-64::freetype-2.12.1-hdaf720e_2
gettext conda-forge/win-64::gettext-0.21.1-h5728263_0
glib conda-forge/win-64::glib-2.78.3-h12be248_0
glib-tools conda-forge/win-64::glib-tools-2.78.3-h12be248_0
gst-plugins-base conda-forge/win-64::gst-plugins-base-1.22.8-h001b923_1
gstreamer conda-forge/win-64::gstreamer-1.22.8-hb4038d2_1
icu conda-forge/win-64::icu-73.2-h63175ca_0
kiwisolver conda-forge/win-64::kiwisolver-1.4.5-py310h232114e_1
lcms2 conda-forge/win-64::lcms2-2.16-h67d730c_0
lerc conda-forge/win-64::lerc-4.0.0-h63175ca_0
libbrotlicommon conda-forge/win-64::libbrotlicommon-1.1.0-hcfcfb64_1
libbrotlidec conda-forge/win-64::libbrotlidec-1.1.0-hcfcfb64_1
libbrotlienc conda-forge/win-64::libbrotlienc-1.1.0-hcfcfb64_1
libclang conda-forge/win-64::libclang-15.0.7-default_h77d9078_3
libclang13 conda-forge/win-64::libclang13-15.0.7-default_h77d9078_3
libdeflate conda-forge/win-64::libdeflate-1.19-hcfcfb64_0
libglib conda-forge/win-64::libglib-2.78.3-h16e383f_0
libjpeg-turbo conda-forge/win-64::libjpeg-turbo-3.0.0-hcfcfb64_1
libogg conda-forge/win-64::libogg-1.3.4-h8ffe710_1
libpng conda-forge/win-64::libpng-1.6.39-h19919ed_0
libtiff conda-forge/win-64::libtiff-4.6.0-h6e2ebb7_2
libvorbis conda-forge/win-64::libvorbis-1.3.7-h0e60522_0
libwebp-base conda-forge/win-64::libwebp-base-1.3.2-hcfcfb64_0
libxcb conda-forge/win-64::libxcb-1.15-hcd874cb_0
m2w64-gcc-libgfor~ conda-forge/win-64::m2w64-gcc-libgfortran-5.3.0-6
m2w64-gcc-libs conda-forge/win-64::m2w64-gcc-libs-5.3.0-7
m2w64-gcc-libs-co~ conda-forge/win-64::m2w64-gcc-libs-core-5.3.0-7
m2w64-gmp conda-forge/win-64::m2w64-gmp-6.1.0-2
m2w64-libwinpthre~ conda-forge/win-64::m2w64-libwinpthread-git-5.0.0.4634.697f757-2
matplotlib conda-forge/win-64::matplotlib-3.8.2-py310h5588dad_0
matplotlib-base conda-forge/win-64::matplotlib-base-3.8.2-py310hc9baf74_0
msys2-conda-epoch conda-forge/win-64::msys2-conda-epoch-20160418-1
munkres conda-forge/noarch::munkres-1.1.4-pyh9f0ad1d_0
openjpeg conda-forge/win-64::openjpeg-2.5.0-h3d672ee_3
pcre2 conda-forge/win-64::pcre2-10.42-h17e33f8_0
pillow conda-forge/win-64::pillow-10.2.0-py310h1e6a543_0
ply conda-forge/noarch::ply-3.11-py_1
pthread-stubs conda-forge/win-64::pthread-stubs-0.4-hcd874cb_1001
pyparsing conda-forge/noarch::pyparsing-3.1.1-pyhd8ed1ab_0
pyqt conda-forge/win-64::pyqt-5.15.9-py310h1fd54f2_5
pyqt5-sip conda-forge/win-64::pyqt5-sip-12.12.2-py310h00ffb61_5
python-dateutil conda-forge/noarch::python-dateutil-2.8.2-pyhd8ed1ab_0
qt-main conda-forge/win-64::qt-main-5.15.8-h9e85ed6_18
sip conda-forge/win-64::sip-6.7.12-py310h00ffb61_0
six conda-forge/noarch::six-1.16.0-pyh6c4a22f_0
toml conda-forge/noarch::toml-0.10.2-pyhd8ed1ab_0
tomli conda-forge/noarch::tomli-2.0.1-pyhd8ed1ab_0
tornado conda-forge/win-64::tornado-6.3.3-py310h8d17308_1
unicodedata2 conda-forge/win-64::unicodedata2-15.1.0-py310h8d17308_0
xorg-libxau conda-forge/win-64::xorg-libxau-1.0.11-hcd874cb_0
xorg-libxdmcp conda-forge/win-64::xorg-libxdmcp-1.1.3-hcd874cb_0
Downloading and Extracting Packages
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
julia> figure(1)
C:\Users\test_julia>
I'm experiencing the same issue, also on Windows 11. I have tried Julia v. 1.6.7 and v. 1.10.0, and reinstalled everything several times, but I get the same issue every time. Matplotlib works fine when called from Python. I also tried a different user on the same PC but got the same result. For me, this issue happened after I reinstalled Windows 11 (and Julia and Python); before that, everything was working perfectly.
I got it to work for me. My best guess is that something goes wrong when PyPlot uses Conda to install Matplotlib. So here is what I did to make it work:
- Install Python (check the box to add it to PATH)
- Install Matplotlib as described here: https://matplotlib.org/stable/users/installing/index.html
- Check that Matplotlib works in Python
- Add an environment variable named "PYTHON" that links to the exe-file of the Python version from steps 1 through 3.
- Install Julia
- Check that
ENV["PYTHON"]
in Julia returns the path to the python exe-file from step 4. - Add PyPlot in Julia
After that, when typing using PyPlot
it should not start installing Matplotlib through Conda, but just return. Running figure()
should open an empty figure without crashing.
Did you try:
ENV["PYTHON"]=""
Pkg.build("PyCall")
This installs a version of Python and Matplotlib for Julia only and thus avoids compatibility issues with versions installed outside of Julia.
I tried both of the solutions mentioned in the two previous posts (installing Python and Matplotlib "manually" and then installing the PyPlot package, followed by using PyPlot
and figure(1)
), and also not installing Python at all and building PyPlot, but neither worked. I am still getting a crash as soon as I type figure(1)
. Does anyone know if there is a log file written somewhere before Julia crashes? I should mention that I seem to see a figure window flash briefly on my screen before the crash, so PyPlot seems to be active. I'll add that Matplotlib invoked from Python seems to be working.
Have you tried switching to a different Matplotlib backend? (e.g. set ENV["MPLBACKEND"]="TkAgg"
or ="QtAgg"
or ="GTK4Agg"
before loading PyPlot).
Try using the same backend that you are using from Python, as printed by matplotlib.get_backend()
.
I retried the solution of manually installing Python and Matplotlib, setting the Windows environment variable PYTHON, and then reinstalling Julia and PyPlot. It didn't work yesterday, but it worked today. The difference between what I did yesterday versus today is: yesterday I partially cleaned out Julia and PyPlot; today I fully cleaned them out (uninstall julia and delete the entire .julia folder). So this problem is solved for me, and I will close the issue.