我不确定用Pkg.generate()
在Julia中创建的环境是否完全隔离,或者它们是否会继承上层目录树中安装的某些模块/软件包。如果是这种情况,有没有办法开始一个完全空的环境?我认为Base环境是强制性的,对吧?谢谢。
我不确定用Pkg.generate()
在Julia中创建的环境是否完全隔离,或者它们是否会继承上层目录树中安装的某些模块/软件包。如果是这种情况,有没有办法开始一个完全空的环境?我认为Base环境是强制性的,对吧?谢谢。
Julia中的环境是堆叠的 - 有一个默认环境(以Julia版本命名,例如Julia 1.8.x的@1.8
),默认情况下可以从任何活动环境访问。相关文档的部分内容可以在这里找到。
引用自该文档:
第三种也是最后一种环境是通过覆盖其他环境来组合它们,使每个环境中的软件包都可在单个复合环境中使用。这些复合环境称为环境堆栈。Julia
LOAD_PATH
全局定义了一个环境堆栈 - Julia进程所在的环境。如果您希望您的Julia进程仅访问一个项目或软件包目录中的软件包,请将其作为LOAD_PATH
中的唯一条目。
要查看此操作:
julia> Base.LOAD_PATH
3-element Vector{String}:
"@"
"@v#.#"
"@stdlib"
这里@v#.#
是默认环境,而@stdlib
则是标准库(例如像DelimitedFiles
、Statistics
这样的东西)。LOAD_PATH
的帮助条目提供了更详细的信息:
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.
如果你想的话,可以从LOAD_PATH
中删除所有内容:
C:\>set JULIA_LOAD_PATH=""
C:\>julia -q
julia> Base.LOAD_PATH
1-element Vector{String}:
"\"\""