How to install a julia package offline in Julia 1.

2020-07-11 07:17发布

问题:

I have my own julia package works well on Julia 0.6. When I try to upgrade to julia 1.0, I found it's more difficult to add my own package in Julia 1.0. I cannot just put it under pkg.dir(). In my situation, the package is just several files on my local disk and don't rely on anything else except julia itself. I could use it with 'generate' and 'activate' in the new package manager, however, after restart the REPL, I have to redo the 'generate' and 'activate'. Is there a way to install the package perpetually? Thank you!

I tried put my own package files under JULIA_DEPOT_PATH/MyPackageName/src . I also tried put the files under MyPackageName/random-five-char/src/. Neither works.

回答1:

however, after restart the REPL, I have to redo the 'generate' and 'activate'.

In fact, you don't have to. Did you try activate /your/package/path/package_name instead of 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]

Is there a way to install the package perpetually?

IIUC, what you'd like is to install the package in the default environment(e.g. (1.0)). The simplest way to do this is 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


标签: julia