1

I've recently started using JuliaBox for programming in Julia, and I want to use my own modules that I've previously written using the Juno-Atom IDE. I've uploaded the relevant modules to JuliaBox, but I am unable to call them from a JuliaBox notebook. The error message I get is as follows:

using MyModule

ArgumentError: Module MyModule not found in current path.
Run `Pkg.add("MyModule")` to install the MyModule package.

Stacktrace:
 [1] _require(::Symbol) at ./loading.jl:435
 [2] require(::Symbol) at ./loading.jl:405
 [3] include_string(::String, ::String) at ./loading.jl:522

I originally had the module in a separate folder called 'modules', but even after moving it to the main folder (same location as the notebook), I still get the same error message.

I have ascertained the working directory:

pwd()
"/mnt/juliabox"

..and that seems to be the folder where my module is currently stored. At least, that's the directory which is displayed when I try to move the module file on the main JuliaBox screen.

I did try installing the module as an unregistered package under Package Builder (I was getting desperate!), but that didn't work either.

So I'm wondering whether I need to add something to the JULIA_LOAD_PATH in Environment Variables; however, that would seem to rather defeat the purpose of using an online version of Jupyter notebooks, which presumably is to allow easy access anywhere.

Anyway, I've run out of ideas, so if anyone could give me a clue as to where I am going wrong it would be very much appreciated.

Rob
  • 14,746
  • 28
  • 47
  • 65
Mark Birtwistle
  • 362
  • 2
  • 10

2 Answers2

2

If your module file is in the main folder, add it to the LOAD_PATH (it is not added by default). Customize the path if you put your file somewhere else.

 @everywhere push!(LOAD_PATH, homedir())
 import MyModule

or

include("MyModule.jl") # if it is already in pwd()
import MyModule

The issue is not related to JuliaBox or IJulia. That is how you import a Module. You either put the folder in LOAD_PATH or include the file containing the module.

https://docs.julialang.org/en/stable/manual/modules/#Relative-and-absolute-module-paths-1

I believe this issue on Github addressing the problem you are facing: https://github.com/JuliaLang/julia/issues/4600

hckr
  • 5,456
  • 1
  • 20
  • 31
1

I did try installing the module as an unregistered package under Package Builder (I was getting desperate!), but that didn't work either.

I think the package builder functionality is working properly. Just try creating a dummy module with the following structure and the contents:

~/MyModule.jl> tree 
.
├── REQUIRE
└── src
    ├── functions
    │   └── myfunc.jl
    └── MyModule.jl

2 directories, 3 files
~/MyModule.jl> cat REQUIRE 
julia 0.6
~/MyModule.jl> cat src/functions/myfunc.jl 
myfunc(x) = 2x
~/MyModule.jl> cat src/MyModule.jl 
module MyModule

export myfunc

include(joinpath("functions", "myfunc.jl"))

end

Then, git init a repository inside the directory, git add and git commit all the files, add a remote repository (like on GitHub or GitLab) with git remote add, and git push your local repository to the newly added remote repository. You should see that the unregistered package option is working as intended.

All that remains is to call

julia> using MyModule

julia> myfunc(10)
20

EDIT. You can try adding https://github.com/aytekinar/MyModule.jl as an unregistered package to your JuliaBox. That repository hosts the above-mentioned dummy module.

Arda Aytekin
  • 1,231
  • 14
  • 24
  • I was able to register your MyModule module, so clearly the JuliaBox package builder functionality is working. I need to do some more reading up on modules/packages, I'm a bit of a beginner with Julia. I've selected the previous answer as it more directly answers my original question, but thanks for your input. – Mark Birtwistle Apr 04 '18 at 09:58