Pkg.add("PyPlot" or Pkg.build("PyCall") not working

I have tried Pkg.add(“PyPlot”) or Pkg.build(“PyCall”) and both are not working and producing errors.

Does anyone know how I can fix this to run my script?

What is the output of:

versioninfo()

version of Julia is v1.11.5

Can you please copy and paste the output of versioninfo()? It contains more useful information than the Julia version number.

Screenshots are not a good way to share information in this forum. Also if you share error messages, please copy and paste the complete error message as text and put it into your message enclosed in triple backticks, like ```.

And please also share the complete error message.

And did you try:

using Pkg
ENV["PYTHON"]=""
Pkg.build("PyCall")

(If you are building PyCall, you need to do that before using PyCall in the Julia session.)

Since this is in the “New to Julia” category, I wanted to mention there is another package to interface between Python and Julia:

2 Likes

Please see the error I am getting:

julia> Pkg.add(“PyCall”)
Updating registry at C:\Users\vakaorongana kazenan\.julia\registries\General.toml
Resolving package versions…
Updating C:\Users\vakaorongana kazenan\.julia\environments\v1.11\Project.toml
[438e738f] + PyCall v1.96.4
No Changes to C:\Users\vakaorongana kazenan\.julia\environments\v1.11\Manifest.toml
Precompiling project…
✗ PyCall
✗ PyPlot
0 dependencies successfully precompiled in 31 seconds. 478 already precompiled.
2 dependencies errored.
For a report of the errors see julia> err. To retry use pkg> precompile

julia> Pkg.add(“PyPlot”)
Resolving package versions…
No Changes to C:\Users\vakaorongana kazenan\.julia\environments\v1.11\Project.toml
No Changes to C:\Users\vakaorongana kazenan\.julia\environments\v1.11\Manifest.toml
Precompiling project…
✗ PyCall
✗ PyPlot
0 dependencies successfully precompiled in 30 seconds. 478 already precompiled.
2 dependencies errored.
For a report of the errors see julia> err. To retry use pkg> precompile

Well, the error message tells you to type err on the Julia prompt. You did not do that.

Furthermore, we suggested that you do:

using Pkg
ENV["PYTHON"]=""
Pkg.build("PyCall")

BEFORE using PyCall.

You did not do that.

Please try to do that and post the output.

julia> err
1-element ExceptionStack:
Error building PyCall:
┌ Info: Using the Python distribution in the Conda package by default.
└ To use a different Python version, set ENV[“PYTHON”]=“pythoncommand” and re-run Pkg.build(“PyCall”).
ERROR: LoadError: Conda.jl cannot be installed to its default location C:\Users\vakaorongana kazenan.julia\conda\3\x86_64
as Miniconda does not support the installation to a directory with a space or a
non-ASCII character on Windows. The work-around is to install Miniconda to a
user-writable directory by setting the CONDA_JL_HOME environment variable. For
example on Windows:

ENV[“CONDA_JL_HOME”] = raw"C:\Conda-Julia\3"
using Pkg
Pkg.build(“Conda”)

The Julia session need to be restarted. More information is available at
GitHub - JuliaPy/Conda.jl: Conda managing Julia binary dependencies.

Stacktrace:
[1] error(s::String)
@ Base .\error.jl:35
[2] _install_conda(env::String, force::Bool)
@ Conda C:\Users\vakaorongana kazenan.julia\packages\Conda\zReqD\src\Conda.jl:274
[3] _install_conda(env::String)
@ Conda C:\Users\vakaorongana kazenan.julia\packages\Conda\zReqD\src\Conda.jl:270
[4] runconda(args::Cmd, env::String)
@ Conda C:\Users\vakaorongana kazenan.julia\packages\Conda\zReqD\src\Conda.jl:180
[5] add(pkg::String, env::String; channel::String, satisfied_skip_solve::Bool, args::Cmd)
@ Conda C:\Users\vakaorongana kazenan.julia\packages\Conda\zReqD\src\Conda.jl:343
[6] add
@ C:\Users\vakaorongana kazenan.julia\packages\Conda\zReqD\src\Conda.jl:326 [inlined]
[7] top-level scope
@ C:\Users\vakaorongana kazenan.julia\packages\PyCall\1gn3u\deps\build.jl:79
[8] include(fname::String)
@ Main .\sysimg.jl:38
[9] top-level scope
@ none:5
in expression starting at C:\Users\vakaorongana kazenan.julia\packages\PyCall\1gn3u\deps\build.jl:43
Stacktrace:
[1] pkgerror(msg::String)
@ Pkg.Types C:\Users\vakaorongana kazenan\AppData\Local\Programs\Julia-1.11.5\share\julia\stdlib\v1.11\Pkg\src\Types.jl:68
[2] (::Pkg.Operations.var"#67#74"{Bool, Pkg.Types.Context, String, Pkg.Types.PackageSpec, String})()
@ Pkg.Operations C:\Users\vakaorongana kazenan\AppData\Local\Programs\Julia-1.11.5\share\julia\stdlib\v1.11\Pkg\src\Operations.jl:1195
[3] withenv(::Pkg.Operations.var"#67#74"{Bool, Pkg.Types.Context, String, Pkg.Types.PackageSpec, String}, ::Pair{String, String}, ::Vararg{Pair{String}})
@ Base .\env.jl:265
[4] (::Pkg.Operations.var"#118#123"{String, Pkg.Types.EnvCache, Bool, Bool, Bool, Pkg.Operations.var"#67#74"{Bool, Pkg.Types.Context, String, Pkg.Types.PackageSpec, String}, Pkg.Types.PackageSpec})()
@ Pkg.Operations C:\Users\vakaorongana kazenan\AppData\Local\Programs\Julia-1.11.5\share\julia\stdlib\v1.11\Pkg\src\Operations.jl:1935
[5] with_temp_env(fn::Pkg.Operations.var"#118#123"{String, Pkg.Types.EnvCache, Bool, Bool, Bool, Pkg.Operations.var"#67#74"{Bool, Pkg.Types.Context, String, Pkg.Types.PackageSpec, String}, Pkg.Types.PackageSpec}, temp_env::String)
@ Pkg.Operations C:\Users\vakaorongana kazenan\AppData\Local\Programs\Julia-1.11.5\share\julia\stdlib\v1.11\Pkg\src\Operations.jl:1793
[6] (::Pkg.Operations.var"#116#121"{Dict{String, Any}, Bool, Bool, Bool, Pkg.Operations.var"#67#74"{Bool, Pkg.Types.Context, String, Pkg.Types.PackageSpec, String}, Pkg.Types.Context, Pkg.Types.PackageSpec, String, String})(tmp::String)
@ Pkg.Operations C:\Users\vakaorongana kazenan\AppData\Local\Programs\Julia-1.11.5\share\julia\stdlib\v1.11\Pkg\src\Operations.jl:1902
[7] mktempdir(fn::Pkg.Operations.var"#116#121"{Dict{String, Any}, Bool, Bool, Bool, Pkg.Operations.var"#67#74"{Bool, Pkg.Types.Context, String, Pkg.Types.PackageSpec, String}, Pkg.Types.Context, Pkg.Types.PackageSpec, String, String}, parent::String; prefix::String)
@ Base.Filesystem .\file.jl:819
[8] mktempdir(fn::Function, parent::String)
@ Base.Filesystem .\file.jl:815
[9] mktempdir
@ .\file.jl:815 [inlined]
[10] #sandbox#115
@ C:\Users\vakaorongana kazenan\AppData\Local\Programs\Julia-1.11.5\share\julia\stdlib\v1.11\Pkg\src\Operations.jl:1849 [inlined]
[11] build_versions(ctx::Pkg.Types.Context, uuids::Set{Base.UUID}; verbose::Bool)
@ Pkg.Operations C:\Users\vakaorongana kazenan\AppData\Local\Programs\Julia-1.11.5\share\julia\stdlib\v1.11\Pkg\src\Operations.jl:1176
[12] build_versions
@ C:\Users\vakaorongana kazenan\AppData\Local\Programs\Julia-1.11.5\share\julia\stdlib\v1.11\Pkg\src\Operations.jl:1094 [inlined]
[13] build(ctx::Pkg.Types.Context, uuids::Set{Base.UUID}, verbose::Bool)
@ Pkg.Operations C:\Users\vakaorongana kazenan\AppData\Local\Programs\Julia-1.11.5\share\julia\stdlib\v1.11\Pkg\src\Operations.jl:1034
[14] build(ctx::Pkg.Types.Context, pkgs::Vector{Pkg.Types.PackageSpec}; verbose::Bool, kwargs::@Kwargs{io::IOContext{IO}})
@ Pkg.API C:\Users\vakaorongana kazenan\AppData\Local\Programs\Julia-1.11.5\share\julia\stdlib\v1.11\Pkg\src\API.jl:1110
[15] build(pkgs::Vector{Pkg.Types.PackageSpec}; io::IOContext{IO}, kwargs::@Kwargs{})
@ Pkg.API C:\Users\vakaorongana kazenan\AppData\Local\Programs\Julia-1.11.5\share\julia\stdlib\v1.11\Pkg\src\API.jl:159
[16] build(pkgs::Vector{Pkg.Types.PackageSpec})
@ Pkg.API C:\Users\vakaorongana kazenan\AppData\Local\Programs\Julia-1.11.5\share\julia\stdlib\v1.11\Pkg\src\API.jl:148
[17] build
@ C:\Users\vakaorongana kazenan\AppData\Local\Programs\Julia-1.11.5\share\julia\stdlib\v1.11\Pkg\src\API.jl:147 [inlined]
[18] build(pkg::String)
@ Pkg.API C:\Users\vakaorongana kazenan\AppData\Local\Programs\Julia-1.11.5\share\julia\stdlib\v1.11\Pkg\src\API.jl:146
[19] top-level scope
@ REPL[13]:1

Building Conda ─→ C:\Users\vakaorongana kazenan\.julia\scratchspaces\44cfe95a-1eb2-52ea-b672-e2afdf69b78f\b19db3927f0db4151cb86d073689f2428e524576\build.log
Building PyCall → C:\Users\vakaorongana kazenan\.julia\scratchspaces\44cfe95a-1eb2-52ea-b672-e2afdf69b78f\9816a3826b0ebf49ab4926e2b18842ad8b5c8f04\build.log
Error building PyCall:
┌ Info: Using the Python distribution in the Conda package by default.
└ To use a different Python version, set ENV[“PYTHON”]=“pythoncommand” and re-run Pkg.build(“PyCall”).
ERROR: LoadError: Conda.jl cannot be installed to its default location C:\Users\vakaorongana kazenan.julia\conda\3\x86_64
as Miniconda does not support the installation to a directory with a space or a
non-ASCII character on Windows. The work-around is to install Miniconda to a
user-writable directory by setting the CONDA_JL_HOME environment variable. For
example on Windows:

ENV[“CONDA_JL_HOME”] = raw"C:\Conda-Julia\3"
using Pkg
Pkg.build(“Conda”)

The Julia session need to be restarted. More information is available at
GitHub - JuliaPy/Conda.jl: Conda managing Julia binary dependencies.

I think the error message is clear. Your home directory contains a space character, which is not supported. There is a workaround for this problem, let me search for it.

Step-by-Step Solution

  1. Create a New Directory Without Spaces
    For example, create C:\Conda-Julia\3 or any path without spaces or special characters.
c:
cd \
mkdir Conda-Julia
cd Conda-Julia
mkdir 3
  1. Set the CONDA_JL_HOME Environment Variable
    This tells Julia’s Conda.jl to install Miniconda in a directory without problematic characters.
    In your Julia REPL, run:
ENV["CONDA_JL_HOME"] = raw"C:\Conda-Julia\3"
  1. Rebuild Conda and PyCall
    In Julia, run:
using Pkg
Pkg.add("Conda")
Pkg.build("Conda")
Pkg.add("PyCall")
Pkg.build("PyCall")

This will install Miniconda and configure PyCall to use it in the new location
4. Install PyPlot
Now, you can safely install PyPlot:

Pkg.add("PyPlot")

PyPlot should now install and build without issues related to the user directory name.

1 Like

Thank you,

1 Like

[ Info: Precompiling PyPlot [d330b81b-6aea-500a-939a-2ce795aea3ee] (cache misses: wrong dep version loaded (2))
ERROR: LoadError: InitError: Using Conda.jl python, but location of C:\Conda-Julia\3\python.exe seems to have moved to C:\Users\vakaorongana kazenan.julia\conda\3\x86_64. Re-run Pkg.build(“PyCall”) and restart Julia.
Stacktrace:
[1] error(s::String)
@ Base .\error.jl:35
[2] init()
@ PyCall C:\Users\vakaorongana kazenan.julia\packages\PyCall\1gn3u\src\pyinit.jl:145
[3] run_module_init(mod::Module, i::Int64)

Did you try that?

I mean, usually the error messages give you very useful hints. In 80% of the cases just follow them and your problem is solved.

You could also restart Julia and then do:

ENV["CONDA_JL_HOME"] = raw"C:\Conda-Julia\3"
using Pkg
Pkg.build("PyCall")

Does that work?