# Using PyPlot on MacOS

**URL:** <https://discourse.julialang.org/t/using-pyplot-on-macos/123512>\
**Category:** General Usage\
**Tags:** question\
**Created:** [December 5, 2024, 7:11pm UTC](https://discourse.julialang.org/t/using-pyplot-on-macos/123512 "2024-12-05T19:11:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Domenico\_Lahaye](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/domenico_lahaye/32/203728_2.png) [@Domenico\_Lahaye](https://discourse.julialang.org/u/Domenico_Lahaye)\
**Post date:** [December 5, 2024, 7:11pm UTC](https://discourse.julialang.org/t/using-pyplot-on-macos/123512/1 "2024-12-05T19:11:45Z")

</div>

Apologies for being confused and not very constructive.

This issue was discussed on this forum before. I thought I had this fixed after updating conda. It was working. But then inadvertly I broke it again.

I am trying to add PyPlot as package. The precompile however fails.

```julia
(@v1.10) pkg> precompile
Precompiling project...
  ✗ PyPlot
  0 dependencies successfully precompiled in 1 seconds. 69 already precompiled.

ERROR: The following 1 direct dependency failed to precompile 

PyPlot [d330b81b-6aea-500a-939a-2ce795aea3ee]

Failed to precompile PyPlot [d330b81b-6aea-500a-939a-2ce795aea3ee] to "/Users/djplahaye/.julia/compiled/v1.10/PyPlot/jl_rmUvog".
ImportError: No module named sit

```

and status is

```julia
(@v1.10) pkg> st
Status `~/.julia/environments/v1.10/Project.toml`
  [c87230d0] FFMPEG v0.4.2 `https://github.com/JuliaIO/FFMPEG.jl#master`
  [7073ff75] IJulia v1.26.0
  [d330b81b] PyPlot v2.11.5

```

Help is much appreciated.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [December 5, 2024, 7:35pm UTC](https://discourse.julialang.org/t/using-pyplot-on-macos/123512/2 "2024-12-05T19:35:26Z")

</div>

> [@Domenico\_Lahaye](#):
>
> `ImportError: No module named site`

This indicates a broken Python environment. I’m guessing `ENV["PYTHON"]` is set to the name of a broken python?

If you make sure `ENV["PYTHON"]=""` when you build PyPlot/PyCall, it will install its own Conda distro which should work.

---

<div class="post-metadata">

**Author:** ![Domenico\_Lahaye](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/domenico_lahaye/32/203728_2.png) [@Domenico\_Lahaye](https://discourse.julialang.org/u/Domenico_Lahaye)\
**Post date:** [December 5, 2024, 9:46pm UTC](https://discourse.julialang.org/t/using-pyplot-on-macos/123512/3 "2024-12-05T21:46:08Z")

</div>

Apologies for being confused.

Here is output of ENV in the REPL

```julia
julia> ENV
Base.EnvDict with 31 entries:
  "TERM_PROGRAM" => "Apple_Terminal"
  "SHELL" => "/bin/zsh"
  "TERM" => "xterm-256color"
  "TMPDIR" => "/var/folders/01/8xpmjxp12q191smq8y_d32p0…
  "TERM_PROGRAM_VERSION" => "440"
  "TERM_SESSION_ID" => "6DBB1EDD-EC3A-4709-BD48-62E998E7BE3A"
  "USER" => "djplahaye"
  "SSH_AUTH_SOCK" => "/private/tmp/com.apple.launchd.jYmmV99Uq…
  "PATH" => "/Users/djplahaye/.juliaup/bin:/opt/anaco…
  "__CFBundleIdentifier" => "com.apple.Terminal"
  "PWD" => "/Users/djplahaye/.julia/packages/Harmoni…
  "XPC_FLAGS" => "0x0"
  "XPC_SERVICE_NAME" => "0"
  "SHLVL" => "1"
  "HOME" => "/Users/djplahaye"
  "LOGNAME" => "djplahaye"
  "DISPLAY" => "/private/tmp/com.apple.launchd.7qyiQZt2w…
  "OLDPWD" => "/Users/djplahaye/.julia/packages/Harmoni…
  "CONDA_EXE" => "/opt/anaconda3/bin/conda"
  "_CE_M" => ""
  "_CE_CONDA" => ""
  "CONDA_PYTHON_EXE" => "/opt/anaconda3/bin/python"
  "CONDA_SHLVL" => "1"
  "CONDA_PREFIX" => "/opt/anaconda3"
  "CONDA_DEFAULT_ENV" => "base"
  "CONDA_PROMPT_MODIFIER" => "(base) "
  "LC_CTYPE" => "UTF-8"
  "_" => "/Users/djplahaye/.juliaup/bin/julia"
  "__CF_USER_TEXT_ENCODING" => "0x1F5:0x0:0x0"
  "OPENBLAS_MAIN_FREE" => "1"
  "OPENBLAS_DEFAULT_NUM_THREADS" => "1"

```

What could I check from here on?

Thanks.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [December 6, 2024, 1:32am UTC](https://discourse.julialang.org/t/using-pyplot-on-macos/123512/4 "2024-12-06T01:32:19Z")

</div>

What happens if you do `ENV["PYTHON"]=""` followed by `add PyCall` and `build PyCall` at the `pkg>` prompt? If that works, does `using PyCall` then work?

---

<div class="post-metadata">

**Author:** ![Domenico\_Lahaye](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/domenico_lahaye/32/203728_2.png) [@Domenico\_Lahaye](https://discourse.julialang.org/u/Domenico_Lahaye)\
**Post date:** [December 6, 2024, 7:09am UTC](https://discourse.julialang.org/t/using-pyplot-on-macos/123512/5 "2024-12-06T07:09:46Z")

</div>

Thanks!

I proceeded in three steps.

First, I made sure to have ENV[“PYTHON”]=“”

```julia
julia> ENV
Base.EnvDict with 32 entries:
  "TERM_PROGRAM" => "Apple_Terminal"
  "SHELL" => "/bin/zsh"
  "TERM" => "xterm-256color"
  "TMPDIR" => "/var/folders/01/8xpmjxp12q191smq8y_d32p0…
  "TERM_PROGRAM_VERSION" => "440"
  "TERM_SESSION_ID" => "6DBB1EDD-EC3A-4709-BD48-62E998E7BE3A"
  "USER" => "djplahaye"
  "SSH_AUTH_SOCK" => "/private/tmp/com.apple.launchd.jYmmV99Uq…
  "PATH" => "/Users/djplahaye/.juliaup/bin:/opt/anaco…
  "__CFBundleIdentifier" => "com.apple.Terminal"
  "PWD" => "/Users/djplahaye/.julia/packages/Harmoni…
  "XPC_FLAGS" => "0x0"
  "XPC_SERVICE_NAME" => "0"
  "SHLVL" => "1"
  "HOME" => "/Users/djplahaye"
  "LOGNAME" => "djplahaye"
  "DISPLAY" => "/private/tmp/com.apple.launchd.7qyiQZt2w…
  "OLDPWD" => "/Users/djplahaye/.julia/packages/Harmoni…
  "CONDA_EXE" => "/opt/anaconda3/bin/conda"
  "_CE_M" => ""
  "_CE_CONDA" => ""
  "CONDA_PYTHON_EXE" => "/opt/anaconda3/bin/python"
  "CONDA_SHLVL" => "1"
  "CONDA_PREFIX" => "/opt/anaconda3"
  "CONDA_DEFAULT_ENV" => "base"
  "CONDA_PROMPT_MODIFIER" => "(base) "
  "LC_CTYPE" => "UTF-8"
  "_" => "/Users/djplahaye/.juliaup/bin/julia"
  "__CF_USER_TEXT_ENCODING" => "0x1F5:0x0:0x0"
  "OPENBLAS_MAIN_FREE" => "1"
  "OPENBLAS_DEFAULT_NUM_THREADS" => "1"
  "PYTHON" => ""

```

Second, at the pkg\> prompt, I added and build PyCall

```julia
(@v1.10) pkg> add PyCall 
   Resolving package versions...
    Updating `~/.julia/environments/v1.10/Project.toml`
  [438e738f] + PyCall v1.96.4
  No Changes to `~/.julia/environments/v1.10/Manifest.toml`

(@v1.10) pkg> build PyCall 
    Building Conda ─→ `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/b19db3927f0db4151cb86d073689f2428e524576/build.log`
    Building PyCall → `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/9816a3826b0ebf49ab4926e2b18842ad8b5c8f04/build.log`
Precompiling project...
  1 dependency successfully precompiled in 5 seconds. 68 already precompiled. 1 skipped during auto due to previous errors.

```

At this stage, using Pycall in the REPL works

```julia
using PyCall 

```

Third, I repeated Step-2 above PyPlot

```julia
(@v1.10) pkg> add PyPlot 
   Resolving package versions...
  No Changes to `~/.julia/environments/v1.10/Project.toml`
  No Changes to `~/.julia/environments/v1.10/Manifest.toml`

(@v1.10) pkg> build PyPlot 
    Building Conda ─→ `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/b19db3927f0db4151cb86d073689f2428e524576/build.log`
    Building PyCall → `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/9816a3826b0ebf49ab4926e2b18842ad8b5c8f04/build.log`

```

Interestingly, with this, using PyPlot in the REPL then results in output I had not seen before

```julia
julia> using PyPlot 
Precompiling PyPlot
  1 dependency successfully precompiled in 2 seconds. 17 already precompiled.
[ Info: Installing matplotlib via the Conda matplotlib package...
[ Info: Running `conda install -y matplotlib` in root environment
Channels:
 - defaults
Platform: osx-arm64
Collecting package metadata (repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /Users/djplahaye/.julia/conda/3

  added / updated specs:
    - matplotlib

The following packages will be downloaded:

    package | build
    ---------------------------|-----------------
    brotli-1.0.9 | h80987f9_8 20 KB
    brotli-bin-1.0.9 | h80987f9_8 18 KB
    contourpy-1.3.1 | py312h48ca7d4_0 264 KB
    cycler-0.11.0 | pyhd3eb1b0_0 12 KB
    fonttools-4.51.0 | py312h80987f9_0 2.8 MB
    freetype-2.12.1 | h1192e45_0 570 KB
    jpeg-9e | h80987f9_3 245 KB
    kiwisolver-1.4.4 | py312h313beb8_0 54 KB
    lcms2-2.12 | hba8e193_0 273 KB
    lerc-3.0 | hc377ac9_0 115 KB
    libbrotlicommon-1.0.9 | h80987f9_8 70 KB
    libbrotlidec-1.0.9 | h80987f9_8 29 KB
    libbrotlienc-1.0.9 | h80987f9_8 291 KB
    libdeflate-1.17 | h80987f9_1 55 KB
    libpng-1.6.39 | h80987f9_0 283 KB
    libtiff-4.5.1 | h313beb8_0 496 KB
    libwebp-base-1.3.2 | h80987f9_1 303 KB
    matplotlib-3.9.2 | py312hca03da5_1 8 KB
    matplotlib-base-3.9.2 | py312h7ef442a_1 7.8 MB
    openjpeg-2.5.2 | h54b8e55_0 324 KB
    pillow-11.0.0 | py312hfaf4e14_0 893 KB
    pyparsing-3.2.0 | py312hca03da5_0 473 KB
    python-dateutil-2.9.0post0 | py312hca03da5_2 320 KB
    six-1.16.0 | pyhd3eb1b0_1 18 KB
    tornado-6.4.1 | py312h80987f9_0 866 KB
    unicodedata2-15.1.0 | py312h80987f9_0 532 KB
    ------------------------------------------------------------
                                           Total: 17.0 MB

The following NEW packages will be INSTALLED:

  brotli pkgs/main/osx-arm64::brotli-1.0.9-h80987f9_8 
  brotli-bin pkgs/main/osx-arm64::brotli-bin-1.0.9-h80987f9_8 
  contourpy pkgs/main/osx-arm64::contourpy-1.3.1-py312h48ca7d4_0 
  cycler pkgs/main/noarch::cycler-0.11.0-pyhd3eb1b0_0 
  fonttools pkgs/main/osx-arm64::fonttools-4.51.0-py312h80987f9_0 
  freetype pkgs/main/osx-arm64::freetype-2.12.1-h1192e45_0 
  jpeg pkgs/main/osx-arm64::jpeg-9e-h80987f9_3 
  kiwisolver pkgs/main/osx-arm64::kiwisolver-1.4.4-py312h313beb8_0 
  lcms2 pkgs/main/osx-arm64::lcms2-2.12-hba8e193_0 
  lerc pkgs/main/osx-arm64::lerc-3.0-hc377ac9_0 
  libbrotlicommon pkgs/main/osx-arm64::libbrotlicommon-1.0.9-h80987f9_8 
  libbrotlidec pkgs/main/osx-arm64::libbrotlidec-1.0.9-h80987f9_8 
  libbrotlienc pkgs/main/osx-arm64::libbrotlienc-1.0.9-h80987f9_8 
  libdeflate pkgs/main/osx-arm64::libdeflate-1.17-h80987f9_1 
  libpng pkgs/main/osx-arm64::libpng-1.6.39-h80987f9_0 
  libtiff pkgs/main/osx-arm64::libtiff-4.5.1-h313beb8_0 
  libwebp-base pkgs/main/osx-arm64::libwebp-base-1.3.2-h80987f9_1 
  matplotlib pkgs/main/osx-arm64::matplotlib-3.9.2-py312hca03da5_1 
  matplotlib-base pkgs/main/osx-arm64::matplotlib-base-3.9.2-py312h7ef442a_1 
  openjpeg pkgs/main/osx-arm64::openjpeg-2.5.2-h54b8e55_0 
  pillow pkgs/main/osx-arm64::pillow-11.0.0-py312hfaf4e14_0 
  pyparsing pkgs/main/osx-arm64::pyparsing-3.2.0-py312hca03da5_0 
  python-dateutil pkgs/main/osx-arm64::python-dateutil-2.9.0post0-py312hca03da5_2 
  six pkgs/main/noarch::six-1.16.0-pyhd3eb1b0_1 
  tornado pkgs/main/osx-arm64::tornado-6.4.1-py312h80987f9_0 
  unicodedata2 pkgs/main/osx-arm64::unicodedata2-15.1.0-py312h80987f9_0 

Downloading and Extracting Packages:
                                                                              
Preparing transaction: done                                                   
Verifying transaction: done                                                   
Executing transaction: done                                                   
Fontconfig warning: ignoring UTF-8: not a valid region tag                    
Matplotlib is building the font cache; this may take a moment.

```

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [December 6, 2024, 1:08pm UTC](https://discourse.julialang.org/t/using-pyplot-on-macos/123512/6 "2024-12-06T13:08:18Z")

</div>

> [@Domenico\_Lahaye](#):
>
> Interestingly, with this, using PyPlot in the REPL then results in output I had not seen before

That happens the first time you load it — since it’s using it’s own Conda installation, the very first time you load PyPlot it installs Matplotlib.

Sounds like you had previously configured PyCall to use some other Python installation on your system, one that is currently broken. Glad it is working for you now.
