3

I am trying to set the JULIA_LOAD_PATH as already discussed here Github issue and Julia Docu. I try to run JULIA_LOAD_PATH= "/mypath/bla:$JULIA_LOAD_PATH" in a julia-session, but get the following error:

UndefVarError: JULIA_LOAD_PATH not defined

Stacktrace:
 [1] top-level scope at In[23]:1

I did already do a using Base statement, in case the variable is defined in the Base module, but it did not really help.

How can I add a folder to the julia load-path variable, such that I can import packages from there? Thanks in advance!

cpernul
  • 137
  • 5

1 Answers1

2

JULIA_LOAD_PATH is a system environment variable you may set outside of Julia in your system. You are looking for Base.load_path(), which can be displayed with

julia>Base.load_path()

and added to with

julia>push!(Base.load_path(), "mydirectory")

See also help for LOAD_PATH.

Bill
  • 5,600
  • 15
  • 27
  • Docs are confusing. Help for ``LOAD_PATH`` recommends precisely what the OP tried. I don't see a reference to ``Base.load_path()`` in these docs: https://docs.julialang.org/en/v1/manual/environment-variables/ Having said that, querying ``Base.load_path()`` returned a list, but pushing with ``push!(Base.load_path(), "mydirectory")`` gave me ``"ERROR: LoadError: syntax: missing comma or ) in argument list"`` (with perfectly formed directory that I can ``cd()`` to)... – PatrickT Apr 14 '21 at 08:50
  • PatrickT, this may be a version issue, if you have an older Julia installation. See the current 1.6 docs at https://docs.julialang.org/en/v1/base/constants/#Base.LOAD_PATH, which do mention load_path() though not with its usage. – Bill Apr 16 '21 at 05:38
  • Thanks Bill. I have the latest Julia (stable release) and the docs make for difficult reading, but after commenting above I found that ``push!(LOAD_PATH, "mydirectory")`` worked for me, for whatever reason... :-) – PatrickT Apr 16 '21 at 06:12