Importing modules after having included them in the Main module

Hi all,
I want to import some modules containing variables and functions for my project.
Down below is a simplified version of my Main module (forward / in Linux). Why does such an error occur ?

module Main
include("Modules/ModFunc.jl") # this works
import ModFunc # the error occurs here
end

WARNING: replacing module Main.
ERROR: LoadError: ArgumentError: Package ModFunc not found in current path:

  • Run import Pkg; Pkg.add("ModFunc") to install the ModFunc package.

Writing instead

module Main
push!(LOAD_PATH, "./Modules")
include("ModFunc.jl")
import ModFunc
end

generates the output:

WARNING: replacing module Main.
ERROR: LoadError: could not open file /home/…/FileWhereMyMainIs/ModFunc.jl

Thank you for your attention :slight_smile:

EDIT: the module looks like

module ModFunc
export func
function func()
    return 0
end
end

Use import .ModFunc (with a dot) instead.

3 Likes

Thank you very much ! Do you have an explanation on the difference between with or without the dot ?

The ModFunc in import ModFunc is an absolute module path, i.e., ModFunc is only found if a module with that name is in the LOAD_PATH. On the other hand, .ModFunc (with dot) is a relative module path, i.e., it looks for modules relative to the current module.

This is described here in the manual.

3 Likes

Thank you !