# Importing modules after having included them in the Main module

**URL:** https://discourse.julialang.org/t/importing-modules-after-having-included-them-in-the-main-module/54836
**Category:** General Usage
**Tags:** question, module
**Created:** [February 8, 2021, 10:35am UTC](https://discourse.julialang.org/t/importing-modules-after-having-included-them-in-the-main-module/54836 "2021-02-08T10:35:45Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Valery](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/valery/32/21803_2.png) [@Valery](https://discourse.julialang.org/u/Valery)
#### Post date: [February 8, 2021, 10:35am UTC](https://discourse.julialang.org/t/importing-modules-after-having-included-them-in-the-main-module/54836/1 "2021-02-08T10:35:45Z")

</div>

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 ?

```julia
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

```julia
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 🙂

EDIT: the module looks like

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

```

---

<div class="post-metadata">

### Author: ![sostock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sostock/32/5546_2.png) [@sostock](https://discourse.julialang.org/u/sostock)
#### Post date: [February 8, 2021, 11:37am UTC](https://discourse.julialang.org/t/importing-modules-after-having-included-them-in-the-main-module/54836/2 "2021-02-08T11:37:29Z")

</div>

> [@Valery](#):
>
> ```julia
> module Main
> include("Modules/ModFunc.jl") # this works
> import ModFunc # the error occurs here
> end
> 
> ```

Use `import .ModFunc` (with a dot) instead.

---

<div class="post-metadata">

### Author: ![Valery](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/valery/32/21803_2.png) [@Valery](https://discourse.julialang.org/u/Valery)
#### Post date: [February 8, 2021, 12:14pm UTC](https://discourse.julialang.org/t/importing-modules-after-having-included-them-in-the-main-module/54836/3 "2021-02-08T12:14:44Z")

</div>

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

---

<div class="post-metadata">

### Author: ![sostock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sostock/32/5546_2.png) [@sostock](https://discourse.julialang.org/u/sostock)
#### Post date: [February 8, 2021, 12:39pm UTC](https://discourse.julialang.org/t/importing-modules-after-having-included-them-in-the-main-module/54836/4 "2021-02-08T12:39:41Z")

</div>

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](https://docs.julialang.org/en/v1/manual/modules/#Relative-and-absolute-module-paths) in the manual.

---

<div class="post-metadata">

### Author: ![Valery](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/valery/32/21803_2.png) [@Valery](https://discourse.julialang.org/u/Valery)
#### Post date: [February 8, 2021, 3:11pm UTC](https://discourse.julialang.org/t/importing-modules-after-having-included-them-in-the-main-module/54836/5 "2021-02-08T15:11:23Z")

</div>

Thank you !
