# How to 'using a\_local\_module'

**URL:** <https://discourse.julialang.org/t/how-to-using-a-local-module/57389>\
**Category:** New to Julia\
**Created:** [March 17, 2021, 2:27pm UTC](https://discourse.julialang.org/t/how-to-using-a-local-module/57389 "2021-03-17T14:27:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hpw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hpw/32/22300_2.png) [@hpw](https://discourse.julialang.org/u/hpw)\
**Post date:** [March 17, 2021, 2:27pm UTC](https://discourse.julialang.org/t/how-to-using-a-local-module/57389/1 "2021-03-17T14:27:51Z")

</div>

In a project directory,  
I have a main.jl and a myModule.jl

myModule.jl. contains  
module myModule  
…  
end

In the main.jl,  
how do I use myModule ?

* * *

using myModule  
and  
import myModule

both are for modules already registered by Pkg.

* * *

thanks  
HP

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [March 17, 2021, 2:42pm UTC](https://discourse.julialang.org/t/how-to-using-a-local-module/57389/2 "2021-03-17T14:42:44Z")

</div>

The simplest thing is:

```julia
julia> push!(LOAD_PATH, ".")
4-element Array{String,1}:
 "@"
 "@v#.#"
 "@stdlib"
 "."

julia> using myModule

```

By pushing to `LOAD_PATH`, you tell Julia to also look in the current folder (“.”) when loading modules.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [March 17, 2021, 2:46pm UTC](https://discourse.julialang.org/t/how-to-using-a-local-module/57389/3 "2021-03-17T14:46:19Z")

</div>

For a slightly more advanced version, try this:

- Run `]generate myModule` (pressing the `]` key to get the `pkg>` prompt in Julia)
  - This will create a new `src` folder and a new `src/myModule.jl` file
  - it will also create a `Project.toml` in your current folder

- Copy your module into `src/myModule.jl`
- Run `julia --project`
  - This will look at the `Project.toml` that you just generated

You should then be able to do `using myModule` without any modification of `LOAD_PATH`, as long as you start julia with `julia --project`

The advantage of this approach is that you now have a brand new clean environment for adding any new packages that you might need for working on `myModule`, and you can install packages into that environment without messing up the rest of your system.

---

<div class="post-metadata">

**Author:** ![StevenWhitaker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevenwhitaker/32/9749_2.png) [@StevenWhitaker](https://discourse.julialang.org/u/StevenWhitaker)\
**Post date:** [March 17, 2021, 4:59pm UTC](https://discourse.julialang.org/t/how-to-using-a-local-module/57389/4 "2021-03-17T16:59:02Z")

</div>

A third option is

```julia
include("myModule.jl")
using .myModule # <-- the . is important!

```

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [March 17, 2021, 6:06pm UTC](https://discourse.julialang.org/t/how-to-using-a-local-module/57389/5 "2021-03-17T18:06:39Z")

</div>

In case an explanation helps someone:  
`using .myModule`  
is AFAIK equivalent to  
`using CurrentModule.myModule`.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [March 17, 2021, 6:18pm UTC](https://discourse.julialang.org/t/how-to-using-a-local-module/57389/6 "2021-03-17T18:18:38Z")

</div>

> [@rdeits](#):
>
> For a slightly more advanced version, try this:
> 
> - Run `]generate myModule` (pressing the `]` key to get the `pkg>` prompt in Julia)
> - This will create a new `src` folder and a new `src/myModule.jl` file
> - it will also create a `Project.toml` in your current folder
> 
> - Copy your module into `src/myModule.jl`
> - Run `julia --project`
> - This will look at the `Project.toml` that you just generated

I want to emphasize this more. You should always use `] generate` to use a local module. Just creating the right folder structure won’t make you able to do `using` when it is local.
