首页 > 解决方案 > 如何将依赖项添加到我的 Julia 包中?

问题描述

我在 Julia 中创建了一个包(我们称之为 package_name);文件结构已经与 Project.toml 和 Manifest.toml 文件一起生成,并且我在创建包时已经添加了一些依赖项。

我忘了添加依赖项,我想让 REPL 显示:

(package_name) pkg > 

这样我就可以输入

add dependency_name

我如何让 REPL 显示这个?我想我需要转到包文件夹并(重新)激活包,但我无法使用 cd 导航到它。

显示我应该在 REPL 中输入的确切命令会很有帮助。

标签: julia

解决方案


为了获得包 REPL 模式],您应该在光标位于行首时键入一个右括号。同样,在 package REPL 模式下,您需要BackSpc在提示符后立即键入以返回标准 REPL 模式:

julia> # type ] here to enter the Pkg REPL

# We're now in the Pkg REPL, but the default environment is active
# Let's activate the environment we want
# (replace the path below with "." to activate the environment defined in the current working directory)
(@v1.5) pkg> activate /path/to/package

# Now we see that the correct environment is active
# This is where new dependencies will be added
(package_name) pkg> add DepName

(package_name) pkg> # type BackSpace here to get back to the standard REPL

julia>

此外,通过使用库pkg"..."中定义的字符串宏,您可以在不进入 Pkg REPL 模式的情况下实现相同的目的Pkg

julia> using Pkg

julia> pkg"activate /path/to/package"

julia> pkg"add DepName"

推荐阅读