问题描述
我想在Julia中更改Package目录.默认值为
I want to change the Package directory in Julia. The default is
"~/.julia/v0.4"
我要移动到/opt/julia/v0.4/
.理想情况下,我想将已经安装在~/.julia/v0.4
中的软件包移到新位置.但是,如果那不可能,我可以重新安装它们.
I want to move it to /opt/julia/v0.4/
. Ideally I want to move the packages that are already installed in ~/.julia/v0.4
to the new location. But if that is not possible I can reinstall them.
我该怎么办?
推荐答案
Julia-v0.6和更低版本
可以按照以下步骤更改julia的软件包目录:
Julia-v0.6 and before
one can change julia's package directory by following these steps:
- 在shell中运行
export JULIA_PKGDIR=/your/directory
(或在Windows上手动添加新的环境变量JULIA_PKGDIR
) - 在julia中运行
Pkg.init()
初始化新的包裹系统 - 将
REQUIRE
从旧目录复制到新目录 - 在朱莉娅(Julia)中运行
Pkg.resolve()
- run
export JULIA_PKGDIR=/your/directory
in shell(or manually add a new environment variableJULIA_PKGDIR
on windows) - run
Pkg.init()
in julia to initialize a new package system - copy
REQUIRE
from old directory to the new one - run
Pkg.resolve()
in julia
Julia-v0.7 +
新软件包管理器中的软件包目录"称为 DEPOT_PATH
,可以通过添加环境变量JULIA_DEPOT_PATH
来更改它:
JULIA_DEPOT_PATH=./test julia
julia> DEPOT_PATH
1-element Array{String,1}:
"./test"
(v0.7) pkg> add JSON2
Cloning default registries into /Users/gnimuc/test/registries
有了新的软件包管理器,我们就可以在所需的任何目录中创建隔离的项目,而不必拥有一个巨型软件包目录.每个项目都包含Project.toml
和Manifest.toml
(如果具有某些依赖项).这两个文件记录并保持跟踪项目的环境.
With the new package manager, we are able to create isolated projects in any directory we want instead of having a single giant package directory. Every project contains a Project.toml
and a Manifest.toml
if it has some dependencies. These two files record and keep tracking the environment of the project.
以下信息可能已过时.我强烈建议使用 PkgTemplates.jl 在Julia-v1.0 +中生成项目.
The following info might be obsoleted. I highly recommend to use PkgTemplates.jl for generating projects in Julia-v1.0+.
我们可以在任何文件夹中生成一个新项目,但是必须cd
到项目文件夹中才能using
该项目.下面的(v0.7)
显示我们仍处于默认环境中,因此我们无法使用新生成的项目:
We can generate a new project in any folder, but we must cd
to the project folder to using
the project. The (v0.7)
below shows we're still in the default environment, so we cannot use the newly generated project:
(v0.7) pkg> generate ./MyNewProject
Generating project MyNewProject:
./MyNewProject/Project.toml
./MyNewProject/src/MyNewProject.jl
julia> using MyNewProject
ERROR: ArgumentError: Module MyNewProject not found in current path.
Run `Pkg.add("MyNewProject")` to install the MyNewProject package.
Stacktrace:
[1] require(::Module, ::Symbol) at ./loading.jl:868
如果我们cd
到项目文件夹并activate
环境,那么我们可以using
我们的新项目没有任何问题:
If we cd
to the project folder and activate
the environment, then we can using
our new project without any problems:
shell> cd MyNewProject/
/Users/gnimuc/MyNewProject
(v0.7) pkg> activate .
(MyNewProject) pkg>
julia> using MyNewProject
我认为这是新软件包管理器与旧软件包管理器之间的最大区别.简而言之,我们需要明确地activate
未注册的项目/程序包.
I think that's the big difference between the new package manager and the old one. In short, we need to explicitly activate
our unregistered project/package.
根据文档,我们可以通过add
命令添加未注册的软件包/项目:
According to the doc, we can add an unregistered package/project via add
command:
(HelloWorld) pkg> add https://github.com/fredrikekre/ImportMacros.jl
此命令将目标软件包添加为当前项目的依赖项.在此示例中,我们在HelloWorld
的Manifest.toml
中添加了ImportMacros
.如果我们仅将其用作顶级项目该怎么办?要将其添加到默认环境(v0.7)
?不,我们不需要.答案是我们可以直接将代码cd
下载到该文件夹并以pkg模式运行instantiate
:
This command adds the target package as a dependency of our current project. In this example, we added ImportMacros
in HelloWorld
's Manifest.toml
. What if we just use it as a top-level project? To add it to the default environment (v0.7)
? no, we don't need to. The answer is we can directly download the code, cd
to the folder and run instantiate
in the pkg mode:
shell> git clone https://github.com/Gnimuc/GLTF.jl GLTF
Cloning into 'GLTF'...
remote: Counting objects: 286, done.
remote: Compressing objects: 100% (56/56), done.
remote: Total 286 (delta 73), reused 103 (delta 59), pack-reused 167
Receiving objects: 100% (286/286), 62.16 KiB | 46.00 KiB/s, done.
Resolving deltas: 100% (135/135), done.
shell> cd GLTF
pkg> activate .
(GLTF) pkg> instantiate
Updating registry at `~/.julia/registries/General`
Updating git-repo `https://github.com/JuliaRegistries/General.git`
新的软件包管理器很棒!我们既不需要"using
之前的include
",也不需要将所有内容都打包为仅用于using
.我们现在具有功能齐全的项目"!
The new package manager is great! We neither need "include
before using
" nor make everything as a package just for using
it. We have full-featured "Project" now!
这篇关于在Julia中更改软件包目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!