I was wondering how the environments in Julia work. I thought that by creating a new environment you should be able to see only the packages that are in that environment, but that doesn't seem to be the case. Why is that so?
I.e. if I create a temporary directory and start Julia with that directory as an environment, I still can load modules that are in my general environment, but not in the standard library.
$ mkdir /tmp/jl_temp
$ julia --project=/tmp/jl_temp
(jl_temp) pkg> st
Status `/tmp/jl_temp/Project.toml` (empty project)
julia> using Plots
julia> plot()
This works without giving me any package not installed error. Can someone explain me the reason of this behavior? To me it should not be able to load any package except for the standard library and the packages inside the Project.toml
file of the environment. I could not find any answer in the Documentation of Pkg.jl.
This is managed by how you set the LOAD_PATH
variable. See here.
By default LOAD_PATH
is set to:
julia> LOAD_PATH
3-element Array{String,1}:
"@"
"@v#.#"
"@stdlib"
A full search path is checked in the following way:
(@v1.5) pkg> activate .
Activating new environment at `~/Project.toml`
julia> Base.load_path()
3-element Array{String,1}:
"/home/bkamins/Project.toml"
"/home/bkamins/.julia/environments/v1.5/Project.toml"
"/home/bkamins/julia/share/julia/stdlib/v1.5"
(I have activated project in my current working directory)
So you can see that if some package is not found in your project Julia falls back to the next entries of LOAD_PATH
. If you want to avoid it then modify LOAD_PATH
as needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With