Loading functions defined in .jl file to jupyter notebook

Hi, I’ve defined a .jl file with several functions and I want to use them to do some calculations in jupyter notebook. I tried using include("../src/LinAL.jl") but it gives an error

could not open file /home/tushar/dev/julia/NumericalMethods.jl/src/LinAL.jl

 [1] include(::String) at ./client.jl:457
 [2] top-level scope at In[15]:1
 [3] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1091

I’m not sure how I can load functions from .jl file.

I’m not totally sure what’s wrong but include works using paths (like you did).

What I could imagine is, that you started the Jupyter notebook in a certain folder and you can’t access a folder which is one level with respect to where the notebook was started.

Does the file exist? Does it have read permissions? e.g. try opening Julia in a terminal and running include("/home/tushar/dev/julia/NumericalMethods.jl/src/LinAL.jl")

include should generally work fine in notebooks.

1 Like

I’m get the same error in julia terminal as well. The file exists but I don’t know about read permissions. How do I check for read permissions?

Are you using Unix based or Windows?

For example, in Linux the file could be:

$ ls -l /tmp/lol.jl
-rwx------ 1 root root 374 Jan  4 13:18 /tmp/lol.jl

which means that root is owner and only root can read, write, execute it.

In Julia then it says:

julia> include("/tmp/lol.jl")
ERROR: could not open file /tmp/lol.jl
 [1] include(::String) at ./client.jl:457
 [2] top-level scope at REPL[7]:1
 [3] run_repl(::REPL.AbstractREPL, ::Any) at /build/julia/src/julia-1.5.3/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:288

Did you use autocompletion (via <TAB> in the Julia REPL) to navigate to the file? If a file/path isn’t autocompleted, that would be a hint that probably something with reading permissions is wrong.

1 Like

Yes, I can’t access the folder using autocomplete. How do I fix this?

And it also autocompletes the file you want access?

Can you also try to start the Julia REPL within that folder? Can you include it directly here? (filename without path)

aj can’t :smiley:

Do you have root on the system? Otherwise it could be the case that you aren’t allowed to modify permissions…

How did you create the folder and the file? Can you print out permissions via ls -l in a terminal located where the folder is.

1 Like

I changed the permissions from the properties and can now tab autocomplete.

1 Like