朱莉娅(Julia)如何使用缺少的包裹? [英] How does Julia using behave on missing package?

查看:53
本文介绍了朱莉娅(Julia)如何使用缺少的包裹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

那么,如果您未安装软件包Foo,那么Julia对语句using Foo到底有什么用?据我了解,Julia开始搜索JULIA_LOAD_PATH,但是如何?

So what exactly does Julia do with the statement using Foo if you don't have package Foo installed? As I understood Julia starts searching JULIA_LOAD_PATH, but how?

JULIA_LOAD_PATH的根目录下,必须有一个名为Foo.jl的目录,其中Foo部分可能不区分大小写,并且.jl后缀是可选的?

At the root level of JULIA_LOAD_PATH there must be a directory named Foo.jl where the Foo part may be case insensitive and the .jl suffix is optional?

在这个Foo.jl目录中,必须有一个带有module Foo的源文件名Foo.jl?

And within this Foo.jl directory there must be a source file name Foo.jl with a module Foo?

推荐答案

using隐式调用

using implicitly calls require which indirectly calls find_in_path:

function find_in_path(name::AbstractString, wd = pwd())
    isabspath(name) && return name
    base = name
    # this is why `.jl` suffix is optional
    if endswith(name,".jl")
        base = name[1:end-3]
    else
        name = string(base,".jl")
    end
    if wd !== nothing
        isfile(joinpath(wd,name)) && return joinpath(wd,name)
    end
    for prefix in [Pkg.dir(); LOAD_PATH]
        path = joinpath(prefix, name)
        isfile(path) && return abspath(path)
        path = joinpath(prefix, base, "src", name)
        isfile(path) && return abspath(path)
        path = joinpath(prefix, name, "src", name)
        isfile(path) && return abspath(path)
    end
    return nothing
end

上面的源代码显示name上没有其他操作,这意味着Foo部分应区分大小写敏感(当前取决于文件系统,请参见注释下面).目录名称不必与您的文件名兼容,只要目录位于您的LOAD_PATH中,它就可以是任何名称.

The source code above shows that there is no additional manipulation on name, which means the Foo part should be case sensitive(Currently depend on the filesystem, see the comment below). And the directory name is unnecessary to be compatible with your file name, it can be anything as long as the directory is in your LOAD_PATH.

这篇关于朱莉娅(Julia)如何使用缺少的包裹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆