如果可用,如何在 Julia REPL 中启动时导入包
How to import a package on startup in the Julia REPL, if available
我想在启动 REPL 时随时导入一个包。将以下内容放在 ~/.juliarc.jl
中是一个开始:
if isinteractive()
using Humanize
end
但是如果我在没有这个包的机器上启动 julia
,REPL 将无法启动。
所以我尝试了以下方法:
if isinteractive()
try
using Humanize
catch
end
end
但是由于 Julia 的作用域规则,现在 Humanize
在全局命名空间中甚至不可用。
最佳解决方案是什么?
尝试以下操作 - 在 base Julia 中出现更好的东西之前尝试一下:
humanize_exists = isdir(Pkg.dir("Humanize"))
if humanize_exists && isinteractive(); using Humanize; end
我想在启动 REPL 时随时导入一个包。将以下内容放在 ~/.juliarc.jl
中是一个开始:
if isinteractive()
using Humanize
end
但是如果我在没有这个包的机器上启动 julia
,REPL 将无法启动。
所以我尝试了以下方法:
if isinteractive()
try
using Humanize
catch
end
end
但是由于 Julia 的作用域规则,现在 Humanize
在全局命名空间中甚至不可用。
最佳解决方案是什么?
尝试以下操作 - 在 base Julia 中出现更好的东西之前尝试一下:
humanize_exists = isdir(Pkg.dir("Humanize"))
if humanize_exists && isinteractive(); using Humanize; end