Fatal Python error when running Julia on mac m1 VS Code

Hi everyone! I’m kinda used to Julia given some courses on stochastic simulations and I have never got a problem.
Now I’m struggling with an error which makes the kernel to crash: I’m running Julia1.6.3 on VS Code and when I start the repl and type using PyPlot the below error message appears.
I did some research and tried different solutions from other people who had similar problems but I did not find anything useful that could work.
Could anybody explain me the problem? Thanks in advance

Python path configuration:
  PYTHONHOME = '/Users/salvatorecandita/.julia/conda/3:/Users/salvatorecandita/.julia/conda/3'
  PYTHONPATH = (not set)
  program name = '/Users/salvatorecandita/.julia/conda/3/bin/python'
  isolated = 0
  environment = 1
  user site = 1
  safe_path = 0
  import site = 1
  is in build tree = 0
  stdlib dir = '/Users/salvatorecandita/.julia/conda/3/lib/python3.12'
  sys._base_executable = '/Users/salvatorecandita/.julia/conda/3/bin/python'
  sys.base_prefix = '/Users/salvatorecandita/.julia/conda/3'
  sys.base_exec_prefix = '/Users/salvatorecandita/.julia/conda/3'
  sys.platlibdir = 'lib'
  sys.executable = '/Users/salvatorecandita/.julia/conda/3/bin/python'
  sys.prefix = '/Users/salvatorecandita/.julia/conda/3'
  sys.exec_prefix = '/Users/salvatorecandita/.julia/conda/3'
  sys.path = [
    '/Users/salvatorecandita/.julia/conda/3/lib/python312.zip',
    '/Users/salvatorecandita/.julia/conda/3/lib/python3.12',
    '/Users/salvatorecandita/.julia/conda/3/lib/python3.12/lib-dynload',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00000001e387dc40 (most recent call first):
  <no Python frame>
  ✗ PyPlot
  0 dependencies successfully precompiled in 1 seconds. 17 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/salvatorecandita/.julia/compiled/v1.10/PyPlot/jl_JBHDRp".
Python path configuration:
  PYTHONHOME = '/Users/salvatorecandita/.julia/conda/3:/Users/salvatorecandita/.julia/conda/3'
  PYTHONPATH = (not set)
  program name = '/Users/salvatorecandita/.julia/conda/3/bin/python'
  isolated = 0
  environment = 1
  user site = 1
  safe_path = 0
  import site = 1
  is in build tree = 0
  stdlib dir = '/Users/salvatorecandita/.julia/conda/3/lib/python3.12'
  sys._base_executable = '/Users/salvatorecandita/.julia/conda/3/bin/python'
  sys.base_prefix = '/Users/salvatorecandita/.julia/conda/3'
  sys.base_exec_prefix = '/Users/salvatorecandita/.julia/conda/3'
  sys.platlibdir = 'lib'
  sys.executable = '/Users/salvatorecandita/.julia/conda/3/bin/python'
  sys.prefix = '/Users/salvatorecandita/.julia/conda/3'
  sys.exec_prefix = '/Users/salvatorecandita/.julia/conda/3'
  sys.path = [
    '/Users/salvatorecandita/.julia/conda/3/lib/python312.zip',
    '/Users/salvatorecandita/.julia/conda/3/lib/python3.12',
    '/Users/salvatorecandita/.julia/conda/3/lib/python3.12/lib-dynload',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00000001e387dc40 (most recent call first):
  <no Python frame
Stacktrace:
  [1] pkgerror(msg::String)
    @ Pkg.Types ~/.julia/juliaup/julia-1.10.0+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Pkg/src/Types.jl:70
  [2] precompile(ctx::Pkg.Types.Context, pkgs::Vector{…}; internal_call::Bool, strict::Bool, warn_loaded::Bool, already_instantiated::Bool, timing::Bool, _from_loading::Bool, kwargs::@Kwargs{…})
    @ Pkg.API ~/.julia/juliaup/julia-1.10.0+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Pkg/src/API.jl:1656
  [3] precompile(pkgs::Vector{Pkg.Types.PackageSpec}; io::Base.TTY, kwargs::@Kwargs{_from_loading::Bool})
    @ Pkg.API ~/.julia/juliaup/julia-1.10.0+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Pkg/src/API.jl:159
  [4] precompile
    @ Pkg.API ~/.julia/juliaup/julia-1.10.0+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Pkg/src/API.jl:147 [inlined]
  [5] #precompile#114
    @ Pkg.API ~/.julia/juliaup/julia-1.10.0+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Pkg/src/API.jl:146 [inlined]
  [6] #invokelatest#2
    @ Base ./essentials.jl:889 [inlined]
  [7] invokelatest
    @ Base ./essentials.jl:884 [inlined]
  [8] _require(pkg::Base.PkgId, env::String)
    @ Base ./loading.jl:1957
  [9] __require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base ./loading.jl:1806
 [10] #invoke_in_world#3
    @ Base ./essentials.jl:921 [inlined]
 [11] invoke_in_world
    @ Base ./essentials.jl:918 [inlined]
 [12] _require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base ./loading.jl:1797
 [13] macro expansion
    @ Base ./loading.jl:1784 [inlined]
 [14] macro expansion
    @ Base ./lock.jl:267 [inlined]
 [15] __require(into::Module, mod::Symbol)
    @ Base ./loading.jl:1747
 [16] #invoke_in_world#3
    @ Base ./essentials.jl:921 [inlined]
 [17] invoke_in_world
    @ Base ./essentials.jl:918 [inlined]
 [18] require(into::Module, mod::Symbol)
    @ Base ./loading.jl:1740
 [19] eval
    @ ./boot.jl:385 [inlined]
 [20] eval
    @ ./Base.jl:88 [inlined]
 [21] repleval(m::Module, code::Expr, ::String)
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.66.2/scripts/packages/VSCodeServer/src/repl.jl:229
 [22] (::VSCodeServer.var"#110#112"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.66.2/scripts/packages/VSCodeServer/src/repl.jl:192
 [23] with_logstate(f::Function, logstate::Any)
    @ Base.CoreLogging ./logging.jl:515
 [24] with_logger
    @ ./logging.jl:627 [inlined]
 [25] (::VSCodeServer.var"#109#111"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.66.2/scripts/packages/VSCodeServer/src/repl.jl:193
 [26] #invokelatest#2
    @ Base ./essentials.jl:887 [inlined]
 [27] invokelatest(::Any)
    @ Base ./essentials.jl:884
 [28] (::VSCodeServer.var"#62#63")()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.66.2/scripts/packages/VSCodeServer/src/eval.jl:34
Some type information was truncated. Use `show(err)` to see complete types.```

please check Please read: make it easier to help you

Sorry Eben, I tried my best to post it correctly but It’s the first time… now is it ok?

Now it’s better readable, thank you :slightly_smiling_face:

Could it be somehow a reason (Julia 1.6.3 vs 1.10.0)?

Is there a good reason you are sticking with with 1.6 (apart from 1.6 being LTS)? Generally it is recommended for most users to use the last stable version. Also, it is possible to use PyPlot via Plots.jl frontend AFAIK, maybe that could work.

1 Like

Just checked: 1.6.3 is not even LTS, LTS is 1.6.7.

Specifically for Apple Silicon one should avoid using an old Julia version IMO.

First of all, thanks for your support.
I can swear that I did it by downloading and installing the new version from Julia downloads, I also now tried to do it through JuliaUpdate but got this stacktrace:

 [1] error(s::String)
   @ Base ./error.jl:33
 [2] v_url(version_str::String, os_str::String, arch_str::String, prefer_gui::Bool)
   @ UpdateJulia ~/.julia/packages/UpdateJulia/nPbih/src/UpdateJulia.jl:125
 [3] update_julia(version::String)
   @ UpdateJulia ~/.julia/packages/UpdateJulia/nPbih/src/UpdateJulia.jl:166
 [4] update_julia()
   @ UpdateJulia ~/.julia/packages/UpdateJulia/nPbih/src/UpdateJulia.jl:177
 [5] top-level scope
   @ REPL[5]:1

I managed to install Julia 1.10 also in VS Code, the error is still present, to me it seems an error in python directory but I can’t understand

Python path configuration:
  PYTHONHOME = '/Users/salvatorecandita/.julia/conda/3:/Users/salvatorec
andita/.julia/conda/3'
  PYTHONPATH = (not set)
  program name = '/Users/salvatorecandita/.julia/conda/3/bin/python'
  isolated = 0
  environment = 1
  user site = 1
  safe_path = 0
  import site = 1
  is in build tree = 0
  stdlib dir = '/Users/salvatorecandita/.julia/conda/3/lib/python3.12'
  sys._base_executable = '/Users/salvatorecandita/.julia/conda/3/bin/python'
  sys.base_prefix = '/Users/salvatorecandita/.julia/conda/3'
  sys.base_exec_prefix = '/Users/salvatorecandita/.julia/conda/3'
  sys.platlibdir = 'lib'
  sys.executable = '/Users/salvatorecandita/.julia/conda/3/bin/python'
  sys.prefix = '/Users/salvatorecandita/.julia/conda/3'
  sys.exec_prefix = '/Users/salvatorecandita/.julia/conda/3'
  sys.path = [
    '/Users/salvatorecandita/.julia/conda/3/lib/python312.zip',
    '/Users/salvatorecandita/.julia/conda/3/lib/python3.12',
    '/Users/salvatorecandita/.julia/conda/3/lib/python3.12/lib-dynload',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00000001e387dc40 (most recent call first):
  <no Python frame>

it seems a slight different error but still does not work

If you installed Julia on a Mac by downloading DMG file (which is how it is installed on my computer), you probably should also set the PATH.

Also, even though you already have the current Julia version, installing juliaup could help.

Sorry Eben, I really don’t have any knowledge regarding these stuff…It seems that I have Juliaup but the install from the command line did not work so I went for dmg installation which did not require any path definition
This is what I get from my terminal

It seems that Juliaup is already installed on this system. Please remove the previous installation of Juliaup before you try to install a new version.

Document How To Uninstall · Issue #240 · JuliaLang/juliaup · GitHub mentions

juliaup self uninstall