【问题标题】:How to add dependencies to my Julia package?如何将依赖项添加到我的 Julia 包中?
【发布时间】:2020-09-26 14:16:07
【问题描述】:

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

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

(package_name) pkg > 

这样我就可以打字了

add dependency_name

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

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

【问题讨论】:

    标签: julia


    【解决方案1】:

    为了获得package REPL mode,您应该在光标位于行首时键入右括号]。同样,在包 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 REPL 模式的情况下使用Pkg 库中定义的pkg"..." 字符串宏来实现相同的目的:

    julia> using Pkg
    
    julia> pkg"activate /path/to/package"
    
    julia> pkg"add DepName"
    

    【讨论】:

    • 但这是进入通用“pkg”的包 REPL 模式,我希望它适用于我的特定包,比如 HelloWorld >
    • 我添加了一些关于环境激活的细节。这是你需要的吗?
    猜你喜欢
    • 2012-08-25
    • 1970-01-01
    • 1970-01-01
    • 2023-02-10
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多