My understanding is that Julia visits each of the locations defined in LOAD_PATH
to load package X
until it finds one by the name. So if the default LOAD_PATH
is
julia> LOAD_PATH
3-element Vector{String}:
"@"
"@v#.#"
"@stdlib"
and if you do using PkgA
, Julia will look for the current active environment’s project.toml
first, and if PkgA
is not listed in [deps]
, then move on to the next location, which is @v#.#
(such as environment/v1.8
) and again look inside environment/v1.8/project.toml
, etc.
As a concrete example,
(@v1.8) pkg> dev Example
Resolving package versions...
No Changes to `E:\.julia\environments\v1.8\Project.toml`
No Changes to `E:\.julia\environments\v1.8\Manifest.toml`
julia> import Pkg; cd(Pkg.devdir()); cd("Example")
(@v1.8) pkg> activate .
Activating project at `E:\.julia\dev\Example`
(Example) pkg> st
Project Example v0.5.4
Status `E:\.julia\dev\Example\Project.toml` (empty project)
The active env is Example
. Now I issue in the REPL
, using DataFrames
:
julia> using DataFrames
julia> df = DataFrame()
0×0 DataFrame
DataFrames
successfully loaded even though DataFrames
is missing in the current environment This is because, Julia has discovered DataFrames
from the default env v1.8
instead.
Now here is my real question:
I edit Example.jl
and import DataFrames
within from the module Example
:
module Example
using DataFrames
function test()
df = DataFrame()
end
end
After switching to (Example) pkg>
env, Now I issue using Example
julia> using Example
[ Info: Precompiling Example [7876af07-990d-54b4-ab0e-23690620f79a]
ERROR: LoadError: ArgumentError: Package Example does not have DataFrames in its dependencies:
Unlike the first experiment, strangely, Julia failed to locate DataFrames
.
Why is this so?