Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inheritance in Julia environments

Tags:

julia

It is not clear to me if the environments created in Julia with Pkg.generate() are completely isolated or if they inherit some modules/packages installed in the directories up in the hierarchical directory tree. If this is the case, is there any way to start with a completely empty environment? I think the Base environment is compulsory, right? Thanks.

like image 248
armando Avatar asked Dec 04 '25 01:12

armando


1 Answers

Environments in Julia are stacked - there's a default environment (named after the Julia version, e.g. @1.8 for Julia 1.8.x) which by default is accessible from any active environment. The relevant bits of the documentation can be found here.

Quoting from there:

The third and final kind of environment is one that combines other environments by overlaying several of them, making the packages in each available in a single composite environment. These composite environments are called environment stacks. The Julia LOAD_PATH global defines an environment stack—the environment in which the Julia process operates. If you want your Julia process to have access only to the packages in one project or package directory, make it the only entry in LOAD_PATH.

To see this in action:

julia> Base.LOAD_PATH
3-element Vector{String}:
 "@"
 "@v#.#"
 "@stdlib"

Here @v#.# is the default environment, and @stdlib is as the name suggests the standard library (e.g. things like [at least for now!] DelimitedFiles, Statistics). The help entry for LOAD_PATH provides some more detailed information:

help?> LOAD_PATH
search: LOAD_PATH

  LOAD_PATH

  An array of paths for using and import statements to consider as project environments or package directories when loading code. It is populated based on the JULIA_LOAD_PATH environment variable if set;
  otherwise it defaults to ["@", "@v#.#", "@stdlib"]. Entries starting with @ have special meanings:

    •  @ refers to the "current active environment", the initial value of which is initially determined by the JULIA_PROJECT environment variable or the --project command-line option.

    •  @stdlib expands to the absolute path of the current Julia installation's standard library directory.

    •  @name refers to a named environment, which are stored in depots (see JULIA_DEPOT_PATH) under the environments subdirectory. The user's named environments are stored in ~/.julia/environments so
       @name would refer to the environment in ~/.julia/environments/name if it exists and contains a Project.toml file. If name contains # characters, then they are replaced with the major, minor and
       patch components of the Julia version number. For example, if you are running Julia 1.2 then @v#.# expands to @v1.2 and will look for an environment by that name, typically at
       ~/.julia/environments/v1.2.

  The fully expanded value of LOAD_PATH that is searched for projects and packages can be seen by calling the Base.load_path() function.

You can remove everything from the LOAD_PATH if you want:

C:\>set JULIA_LOAD_PATH=""

C:\>julia -q


julia> Base.LOAD_PATH
1-element Vector{String}:
 "\"\""
like image 108
Nils Gudat Avatar answered Dec 07 '25 21:12

Nils Gudat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!