如何在Julia 1.0中离线安装julia软件包?

时间:2019-01-02 03:09:22

标签: julia

我有自己的julia包,在Julia 0.6上效果很好。当我尝试升级到julia 1.0时,我发现在Julia 1.0中添加自己的软件包更加困难。我不能只是将其放在pkg.dir()下。在我的情况下,程序包只是我本地磁盘上的几个文件,除了julia本身以外,不依赖任何其他文件。我可以在新的程序包管理器中将其与“生成”和“激活”一起使用,但是,重新启动REPL之后,我必须重做“生成”和“激活”。有没有可以永久安装该软件包的方法?谢谢!

我尝试将自己的软件包文件放在JULIA_DEPOT_PATH / MyPackageName / src下。我也尝试将文件放在MyPackageName / random-five-char / src /下。都不行。

1 个答案:

答案 0 :(得分:5)

  

但是,在重新启动REPL之后,我必须重做“生成”和“激活”。

实际上,您不必这样做。您是否尝试用activate /your/package/path/package_name代替activate package_name

(v1.0) pkg> generate ./MyPackgePath/MyPackageName
Generating project MyPackageName:
    ./MyPackgePath/MyPackageName/Project.toml
    ./MyPackgePath/MyPackageName/src/MyPackageName.jl

julia> using MyPackageName  # it won't work because it's not in the default environment
ERROR: ArgumentError: Package MyPackageName not found in current path:
- Run `import Pkg; Pkg.add("MyPackageName")` to install the MyPackageName package.

Stacktrace:
 [1] require(::Module, ::Symbol) at ./loading.jl:823

(v1.0) pkg> activate ./MyPackgePath/MyPackageName  # activate the package's full path to change the current environment(v1.0) to the project environment(MyPackageName)

(MyPackageName) pkg> st
Project MyPackageName v0.1.0
    Status `~/MyPackgePath/MyPackageName/Project.toml`
  (empty environment)

julia> using MyPackageName  # using MyPackageName in the project environment works fine
[ Info: Precompiling MyPackageName [b8c7b058-0e78-11e9-0963-a7719554d5c1]
  

是否可以永久安装该软件包?

IIUC,您想要在默认环境(例如(1.0))中安装该软件包。最简单的方法是dev /your/package/path/package_name

julia> using MyPackageName  # using MyPackageName in the default evironment fails
ERROR: ArgumentError: Package MyPackageName not found in current path:
- Run `import Pkg; Pkg.add("MyPackageName")` to install the MyPackageName package.

Stacktrace:
 [1] require(::Module, ::Symbol) at ./loading.jl:823

(v1.0) pkg> dev ./MyPackgePath/MyPackageName
 Resolving package versions...
  Updating `~/.julia/environments/v1.0/Project.toml`
 [no changes]
  Updating `~/.julia/environments/v1.0/Manifest.toml`
 [no changes]

julia> using MyPackageName  # after `dev`, it's working