Julia crashes when importing PyPlot

Hi everyone,

I decided to give my MacBookPro (13’’ 2019 Intel) a factory reset and now have a nice and clean set-up. Everything works fine, except importing PyPlot in Julia. Unfortunately, I don’t get any error message other than this

julia> import PyPlot
zsh: killed     Julia

because Julia is just dead. Any ideas what could be wrong? I am using Julia 1.12.2 and PyPlot v2.11.6.

Thank you very much,
Georg

What is the output of

versioninfo()

at the Julia prompt?

It gives more details than just the version. That might be useful.
And what is your MacOS version?

The output is

ulia Version 1.12.2
Commit ca9b6662be4 (2025-11-20 16:25 UTC)
Build Info:
  Official https://julialang.org release
Platform Info:
  OS: macOS (x86_64-apple-darwin24.0.0)
  CPU: 8 × Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
  WORD_SIZE: 64
  LLVM: libLLVM-18.1.7 (ORCJIT, skylake)
  GC: Built with stock GC
Threads: 1 default, 1 interactive, 1 GC (on 8 virtual cores)

Mac OS is Sequoia 15.7.2

Can you try these instructions:

rm -rf ~/.julia/conda
mkdir MyProject
cd MyProject
julia --project=.

And on the Julia prompt:

using Pkg
ENV["PYTHON"]=""
pkg"add PyPlot"

This results in the following error:

julia> import PyPlot
ERROR: InitError: could not load library "/Users/georg/.julia/conda/3/x86_64/lib/libpython3.12.dylib"
dlopen(/Users/georg/.julia/conda/3/x86_64/lib/libpython3.12.dylib, 0x0009): tried: '/Users/georg/.julia/conda/3/x86_64/lib/libpython3.12.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/georg/.julia/conda/3/x86_64/lib/libpython3.12.dylib' (no such file), '/Users/georg/.julia/conda/3/x86_64/lib/libpython3.12.dylib' (no such file)
Stacktrace:
  [1] #dlopen#3
    @ ./libdl.jl:120
  [2] dlopen
    @ ./libdl.jl:119 [inlined]
  [3] __init__()
    @ PyCall ~/.julia/packages/PyCall/1gn3u/src/pyinit.jl:149
  [4] run_module_init(mod::Module, i::Int64)
    @ Base ./loading.jl:1440
  [5] register_restored_modules(sv::Core.SimpleVector, pkg::Base.PkgId, path::String)
    @ Base ./loading.jl:1428
  [6] _include_from_serialized(pkg::Base.PkgId, path::String, ocachepath::String, depmods::Vector{Any}; register::Bool)
    @ Base ./loading.jl:1316
  [7] _include_from_serialized
    @ ./loading.jl:1271 [inlined]
  [8] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String, build_id::UInt128, stalecheck::Bool; reasons::Dict{…}, DEPOT_PATH::Vector{…})
    @ Base ./loading.jl:2099
  [9] _require_search_from_serialized
    @ ./loading.jl:2006 [inlined]
 [10] __require_prelocked(pkg::Base.PkgId, env::String)
    @ Base ./loading.jl:2624
 [11] _require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base ./loading.jl:2490
 [12] macro expansion
    @ ./loading.jl:2418 [inlined]
 [13] macro expansion
    @ ./lock.jl:376 [inlined]
 [14] __require(into::Module, mod::Symbol)
    @ Base ./loading.jl:2383
 [15] require(into::Module, mod::Symbol)
    @ Base ./loading.jl:2359
 [16] top-level scope
    @ REPL[4]:1
during initialization of module PyCall
Some type information was truncated. Use `show(err)` to see complete types.

I have had plenty of problems with PyPlot since Julia 1.12, probably related to threads. In the end I migrated to PythonPlot.

Unfortunately this did not help. Adding it resulted in

(@v1.12) pkg> add PythonPlot
   Resolving package versions...
    Updating `~/.julia/environments/v1.12/Project.toml`
  [274fc56d] + PythonPlot v1.0.6
    Updating `~/.julia/environments/v1.12/Manifest.toml`
  [3da002f7] + ColorTypes v0.12.1
  [5ae59095] + Colors v0.13.1
  [992eb4ea] + CondaPkg v0.2.33
  [53c48c17] + FixedPointNumbers v0.8.5
  [0f8b85d8] + JSON3 v1.14.3
  [1914dd2f] + MacroTools v0.5.16
  [0b3b1443] + MicroMamba v0.1.14
  [fa939f87] + Pidfile v1.3.0
  [6099a3de] + PythonCall v0.9.30
  [274fc56d] + PythonPlot v1.0.6
  [6c6a2e73] + Scratch v1.3.0
  [856f2bd8] + StructTypes v1.11.0
  [e17b2a0c] + UnsafePointers v1.0.0
  [81def892] + VersionParsing v1.3.0
⌅ [f8abcde7] + micromamba_jll v1.5.12+0
  [4d7b5844] + pixi_jll v0.41.3+0
  [0dad84c5] + ArgTools v1.1.2
  [f43a241f] + Downloads v1.7.0
  [7b1f6079] + FileWatching v1.11.0
  [4af54fe1] + LazyArtifacts v1.11.0
  [b27032c2] + LibCURL v0.6.4
  [76f85450] + LibGit2 v1.11.0
  [44cfe95a] + Pkg v1.12.0
  [a4e569a6] + Tar v1.10.0
  [deac9b47] + LibCURL_jll v8.15.0+0
  [e37daf67] + LibGit2_jll v1.9.0+0
  [29816b5a] + LibSSH2_jll v1.11.3+1
  [8e850ede] + nghttp2_jll v1.64.0+1
  [3f19e933] + p7zip_jll v17.7.0+0
        Info Packages marked with ⌅ have new versions available but compatibility constraints restrict them from upgrading. To see why use `status --outdated -m`

Now importing the package kills the Julia again. Also removing the package, garbage collecting, and adding it again does not fix the problem. Although, there is no error message when adding it. However, it just crashes.

Do you have similar errors with PyCall.jl and/or PythonCall.jl ?

Adding and importing PythonCall works. After adding PyCall, however, import PyCall results in

julia> import PyCall
ERROR: InitError: could not load library "/Users/georg/.julia/conda/3/x86_64/lib/libpython3.12.dylib"
dlopen(/Users/georg/.julia/conda/3/x86_64/lib/libpython3.12.dylib, 0x0009): tried: '/Users/georg/.julia/conda/3/x86_64/lib/libpython3.12.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/georg/.julia/conda/3/x86_64/lib/libpython3.12.dylib' (no such file), '/Users/georg/.julia/conda/3/x86_64/lib/libpython3.12.dylib' (no such file)
Stacktrace:
  [1] #dlopen#3
    @ ./libdl.jl:120
  [2] dlopen
    @ ./libdl.jl:119 [inlined]
  [3] __init__()
    @ PyCall ~/.julia/packages/PyCall/1gn3u/src/pyinit.jl:149
  [4] run_module_init(mod::Module, i::Int64)
    @ Base ./loading.jl:1440
  [5] register_restored_modules(sv::Core.SimpleVector, pkg::Base.PkgId, path::String)
    @ Base ./loading.jl:1428
  [6] _include_from_serialized(pkg::Base.PkgId, path::String, ocachepath::String, depmods::Vector{Any}; register::Bool)
    @ Base ./loading.jl:1316
  [7] _include_from_serialized
    @ ./loading.jl:1271 [inlined]
  [8] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String, build_id::UInt128, stalecheck::Bool; reasons::Dict{…}, DEPOT_PATH::Vector{…})
    @ Base ./loading.jl:2112
  [9] _require_search_from_serialized
    @ ./loading.jl:2006 [inlined]
 [10] __require_prelocked(pkg::Base.PkgId, env::String)
    @ Base ./loading.jl:2624
 [11] _require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base ./loading.jl:2490
 [12] macro expansion
    @ ./loading.jl:2418 [inlined]
 [13] macro expansion
    @ ./lock.jl:376 [inlined]
 [14] __require(into::Module, mod::Symbol)
    @ Base ./loading.jl:2383
 [15] require(into::Module, mod::Symbol)
    @ Base ./loading.jl:2359
 [16] top-level scope
    @ REPL[6]:1
during initialization of module PyCall
Some type information was truncated. Use `show(err)` to see complete types.

Did you consider setting the Python path manually and rebuilding PyCall.jl?

You may also need to install matplotlib in your python environment.

1 Like

I didn’t.

I am not sure what to set it to. Currently there is no python installation on my machine. To my understanding, this why the Julia packages try building a minimal python installation using miniconda.

There is currently also no entry "Python" in my ENV.

julia> ENV
Base.EnvDict with 29 entries:
  "__CFBundleIdentifier"         => "com.apple.Terminal"
  "TMPDIR"                       => "/var/folders/cd/gnnpy0j96vxc99wdm1p03h5m0000gn/T/"
  "XPC_FLAGS"                    => "0x0"
  "LaunchInstanceID"             => "3A30F679-31A4-4ECD-A483-001718CBA49F"
  "TERM"                         => "xterm-256color"
  "SSH_AUTH_SOCK"                => "/private/tmp/com.apple.launchd.P1NsbIKk3B/Listeners"
  "SECURITYSESSIONID"            => "186a1"
  "XPC_SERVICE_NAME"             => "0"
  "TERM_PROGRAM"                 => "Apple_Terminal"
  "TERM_PROGRAM_VERSION"         => "455.1"
  "TERM_SESSION_ID"              => "38EAAAA0-1A63-4AF6-9FFA-5C6F84A62482"
  "SHELL"                        => "/bin/zsh"
  "HOME"                         => "/Users/georg"
  "LOGNAME"                      => "georg"
  "USER"                         => "georg"
  "PATH"                         => "/Users/georg/.julia/environments/v1.12/.CondaPkg/.pixi/envs/default/bin:/Users/…
  "SHLVL"                        => "1"
  "PWD"                          => "/Users/georg"
  "OLDPWD"                       => "/Users/georg/.julia/conda/3/x86_64/lib"
  "LANG"                         => "de_DE.UTF-8"
  "_"                            => "/Users/georg/.juliaup/bin/julia"
  "__CF_USER_TEXT_ENCODING"      => "0x1F5:0x0:0x3"
  "OPENBLAS_MAIN_FREE"           => "1"
  "OPENBLAS_DEFAULT_NUM_THREADS" => "1"
  "CONDA_PREFIX"                 => "/Users/georg/.julia/environments/v1.12/.CondaPkg/.pixi/envs/default"
  "CONDA_DEFAULT_ENV"            => "/Users/georg/.julia/environments/v1.12/.CondaPkg/.pixi/envs/default"
  "CONDA_SHLVL"                  => "1"
  "CONDA_PROMPT_MODIFIER"        => "(/Users/georg/.julia/environments/v1.12/.CondaPkg/.pixi/envs/default) "
  "PYTHON_JULIACALL_INIT"        => "no"

Should I try installing some Python to my machine and then link it?

For rebuilding PyCall you could try, before adding PyPlot:

julia -e 'ENV["PYTHON"]=""; using Pkg; Pkg.add("PyCall"); Pkg.build("PyCall")'

This installs Python in a subfolder of .julia.

In case that threading should cause a problem you can start Julia with:

julia -t 1

which disables the interactive thread introduced in Julia 1.12.

Unfortunately, this didn’t help. Adding and building PyCall works. starting then using Julia -t 1and adding PyPlot also works. But importing PyPlots results in the following error:


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


==> WARNING: A newer version of conda exists. <==
    current version: 25.9.1
    latest version: 25.11.0

Please update conda by running

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



## Package Plan ##

  environment location: /Users/georg/.julia/conda/3/x86_64

  added / updated specs:
    - matplotlib


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    brotli-1.1.0               |       h1c43f85_4          20 KB  conda-forge
    brotli-bin-1.1.0           |       h1c43f85_4          17 KB  conda-forge
    contourpy-1.3.3            |  py312hd099df3_3         263 KB  conda-forge
    cycler-0.12.1              |     pyhd8ed1ab_1          13 KB  conda-forge
    fonttools-4.60.1           |  py312hacf3034_0         2.7 MB  conda-forge
    freetype-2.14.1            |       h694c41f_0         170 KB  conda-forge
    kiwisolver-1.4.9           |  py312h90e26e8_2          67 KB  conda-forge
    lcms2-2.17                 |       h72f5680_0         221 KB  conda-forge
    lerc-4.0.0                 |       hcca01a6_1         243 KB  conda-forge
    libbrotlicommon-1.1.0      |       h1c43f85_4          66 KB  conda-forge
    libbrotlidec-1.1.0         |       h1c43f85_4          30 KB  conda-forge
    libbrotlienc-1.1.0         |       h1c43f85_4         288 KB  conda-forge
    libdeflate-1.25            |       h517ebb2_0          69 KB  conda-forge
    libfreetype-2.14.1         |       h694c41f_0           8 KB  conda-forge
    libfreetype6-2.14.1        |       h6912278_0         366 KB  conda-forge
    libjpeg-turbo-3.1.2        |       h8616949_0         572 KB  conda-forge
    libpng-1.6.51              |       h380d223_0         292 KB  conda-forge
    libtiff-4.7.1              |       ha0a348c_1         395 KB  conda-forge
    libwebp-base-1.6.0         |       hb807250_0         357 KB  conda-forge
    libxcb-1.17.0              |       hf1f96e2_0         316 KB  conda-forge
    matplotlib-3.10.8          |  py312hb401068_0          17 KB  conda-forge
    matplotlib-base-3.10.8     |  py312h7894933_0         7.9 MB  conda-forge
    munkres-1.1.4              |     pyhd8ed1ab_1          15 KB  conda-forge
    openjpeg-2.5.4             |       h87e8dc5_0         327 KB  conda-forge
    pillow-12.0.0              |  py312h4148a4b_1         939 KB  conda-forge
    pthread-stubs-0.4          |    h00291cd_1002           8 KB  conda-forge
    pyparsing-3.2.5            |     pyhcf101f3_0         102 KB  conda-forge
    python-dateutil-2.9.0.post0|     pyhe01879c_2         228 KB  conda-forge
    qhull-2020.2               |       h3c5361c_5         516 KB  conda-forge
    six-1.17.0                 |     pyhe01879c_1          18 KB  conda-forge
    tornado-6.5.2              |  py312h80b0991_2         829 KB  conda-forge
    unicodedata2-17.0.0        |  py312h80b0991_1         394 KB  conda-forge
    xorg-libxau-1.0.12         |       h8616949_1          13 KB  conda-forge
    xorg-libxdmcp-1.1.5        |       h8616949_1          19 KB  conda-forge
    zlib-ng-2.2.5              |       h55e386d_0         107 KB  conda-forge
    ------------------------------------------------------------
                                           Total:        17.8 MB

The following NEW packages will be INSTALLED:

  brotli             conda-forge/osx-64::brotli-1.1.0-h1c43f85_4 
  brotli-bin         conda-forge/osx-64::brotli-bin-1.1.0-h1c43f85_4 
  contourpy          conda-forge/osx-64::contourpy-1.3.3-py312hd099df3_3 
  cycler             conda-forge/noarch::cycler-0.12.1-pyhd8ed1ab_1 
  fonttools          conda-forge/osx-64::fonttools-4.60.1-py312hacf3034_0 
  freetype           conda-forge/osx-64::freetype-2.14.1-h694c41f_0 
  kiwisolver         conda-forge/osx-64::kiwisolver-1.4.9-py312h90e26e8_2 
  lcms2              conda-forge/osx-64::lcms2-2.17-h72f5680_0 
  lerc               conda-forge/osx-64::lerc-4.0.0-hcca01a6_1 
  libbrotlicommon    conda-forge/osx-64::libbrotlicommon-1.1.0-h1c43f85_4 
  libbrotlidec       conda-forge/osx-64::libbrotlidec-1.1.0-h1c43f85_4 
  libbrotlienc       conda-forge/osx-64::libbrotlienc-1.1.0-h1c43f85_4 
  libdeflate         conda-forge/osx-64::libdeflate-1.25-h517ebb2_0 
  libfreetype        conda-forge/osx-64::libfreetype-2.14.1-h694c41f_0 
  libfreetype6       conda-forge/osx-64::libfreetype6-2.14.1-h6912278_0 
  libjpeg-turbo      conda-forge/osx-64::libjpeg-turbo-3.1.2-h8616949_0 
  libpng             conda-forge/osx-64::libpng-1.6.51-h380d223_0 
  libtiff            conda-forge/osx-64::libtiff-4.7.1-ha0a348c_1 
  libwebp-base       conda-forge/osx-64::libwebp-base-1.6.0-hb807250_0 
  libxcb             conda-forge/osx-64::libxcb-1.17.0-hf1f96e2_0 
  matplotlib         conda-forge/osx-64::matplotlib-3.10.8-py312hb401068_0 
  matplotlib-base    conda-forge/osx-64::matplotlib-base-3.10.8-py312h7894933_0 
  munkres            conda-forge/noarch::munkres-1.1.4-pyhd8ed1ab_1 
  openjpeg           conda-forge/osx-64::openjpeg-2.5.4-h87e8dc5_0 
  pillow             conda-forge/osx-64::pillow-12.0.0-py312h4148a4b_1 
  pthread-stubs      conda-forge/osx-64::pthread-stubs-0.4-h00291cd_1002 
  pyparsing          conda-forge/noarch::pyparsing-3.2.5-pyhcf101f3_0 
  python-dateutil    conda-forge/noarch::python-dateutil-2.9.0.post0-pyhe01879c_2 
  qhull              conda-forge/osx-64::qhull-2020.2-h3c5361c_5 
  six                conda-forge/noarch::six-1.17.0-pyhe01879c_1 
  tornado            conda-forge/osx-64::tornado-6.5.2-py312h80b0991_2 
  unicodedata2       conda-forge/osx-64::unicodedata2-17.0.0-py312h80b0991_1 
  xorg-libxau        conda-forge/osx-64::xorg-libxau-1.0.12-h8616949_1 
  xorg-libxdmcp      conda-forge/osx-64::xorg-libxdmcp-1.1.5-h8616949_1 
  zlib-ng            conda-forge/osx-64::zlib-ng-2.2.5-h55e386d_0 



Downloading and Extracting Packages:
                                                                                                                     
Preparing transaction: done                                                                                          
Verifying transaction: done                                                                                          
Executing transaction: done                                                                                          
zsh: killed     julia -t 1

Have a look at: using PyPlot hangs/kills julia 1.8.5 or 1.9.0 on MacOS · Issue #567 · JuliaPy/PyPlot.jl · GitHub

Try the last suggestion there:

If you are using Python via Conda.jl (which is the default on MacOS), you could try removing conda (rm -rf ~/.julia/conda) and rebuilding PyCall and PyPlot.

If that doesn’t help, create a new issue (you are probably using a newer Julia version than 1.8.5 or 1.9.0).

I know that PyPlot on macOS works for many people, but sometimes a Conda or Matplotlib update might temporarily break it. I don’t have a Mac for testing.

Thanks every one for the fruitful suggestions. I managed to solve the issue. As mentioned by several of you, the main issue is the handling of Python on Mac OS. What helped was

  • installing miniconda right from the anaconda website
  • installing matplotlib using this miniconda instance
  • remove PyPlot and PyCall
  • set Julia ENV[PYTHON]to point to the prepared Python installation
  • (re)add and build PyCall and PyPlot

As I just noticed this is one of the possibilities pointed out in the installation instructions on the PyPlot GitHub page. (Though, they have several suggestions, and only this one worked for me).

Thanks again to everyone for the support.

1 Like