How to set up a Julia module to run in project?

Hi,
I have a module with a couple of functions (which I share with a friend and have a private GitHub repo for). Previously I have just put the code directly in .jl files and done stuff like include("MyFunctions/file_with_functions.jl"). However, I thought that this is what modules are used for, so should probably use them. I tried to simply create a module MyModule with a function, but I have been unable to fetch it…

Here is my file system layout:

This doesn’t seem to work? Is there a way to put a module in a directory within my project and then just load it? Registering as a Julia package seems overly complicated? Then it seems easier to just include all the files directly (and maybe this is the recommended approach)?

Hi,
You are just missing 1 dot.

You have to write

include("MyModule/MyModule.jl")
import .MyModule

Note the dot before MyModule

1 Like

Thanks! :slight_smile:

And note that the include stuff must be run only once, so typically put the include just at the beginning of your script…

1 Like