Using LOAD_PATH from the command line

110 views
Skip to first unread message

David Parks

unread,
May 18, 2016, 9:34:20 PM5/18/16
to julia-users
When running a script from the command line, julia seems to only search for the file in the `HOME` directory. 

It doesn't appear to search the `LOAD_PATH` directory.

Therefore any script not in `HOME` (which is probably every script) would need to be referenced by its full path.

Am I missing something? I can `import` from the REPL, my `LOAD_PATH` is set up properly in `.juliarc`, it seems only logical that this functionality works the same from the command line, so I'm surprised to find it does not.

Tony Kelman

unread,
May 18, 2016, 9:46:12 PM5/18/16
to julia-users
juliarc doesn't get loaded when you run Julia in script mode unless you add the -F (--startup-file=yes) flag.

David Parks

unread,
May 19, 2016, 12:34:13 PM5/19/16
to julia-users
Thanks, that helps, I didn't know about that. It does feel counter intuitive that loading juliarc isn't the default, but maybe there's some hidden logic I don't see.

Though, trying this, I do run into further issues that I'd like to post about.

D:\mydir>julia --startup-file=yes -- myfile.jl arg1 arg2

ERROR
: could not open file d:\myprojects\julia\--
 
in include at boot.jl:261
 
in include_from_node1 at loading.jl:320
 
in process_options at client.jl:280
 
in _start at client.jl:378

So using -- didn't work, which seems to contrast the documentation that describes the command line format as:

julia [switches] -- [programfile] [args...]

And trying it without the -- seperator didn't do much better. I added a `print()` statement to juliarc.jl to validate that it's actually loading. At the command line I do see the print statement I added, "juliarc executed", so I know juliarc was loaded (which sets my LOAD_PATH).

In juliarc I have a series of these statements to set the path:

@everywhere push!(LOAD_PATH,"D:\\path\\to\\my\\files")

I can run `import myfile.jl` from the REPL (without being in the `myfile.jl` directory). But from the command line, it still only looks to HOME.

D:\mydir>julia --startup-file=yes myfile.jl arg1 arg2
juliarc executed
ERROR
: could not open file d:\myprojects\julia\myfile.jl
 
in include at boot.jl:261
 
in include_from_node1 at loading.jl:320
 
in process_options at client.jl:280
 
in _start at client.jl:378

David Parks

unread,
May 19, 2016, 1:53:15 PM5/19/16
to julia-users
One minor correction, it's not looking to my home directory, it's looking to my current directory for the script file. The point remains, it does not use LOAD_PATH to find the script file I want to run. So to run a script I need to specify the full path to the julia script file on the command line every time I want to run it, I cannot take advantage of my LOAD_PATH configuration in the same was as I can in the REPL.

Tony Kelman

unread,
May 19, 2016, 3:21:53 PM5/19/16
to julia-users
What exactly is in myfile.jl? Yes, when you call the julia command-line program on a script file it has to be able to read that script file, so either it's a relative path to where it's run from, or an absolute path. If you want to leverage LOAD_PATH to import modules, then try importing from a -e "..." command.
Reply all
Reply to author
Forward
0 new messages