# How to load a module from the current directory?

**URL:** <https://discourse.julialang.org/t/how-to-load-a-module-from-the-current-directory/21727>\
**Category:** New to Julia\
**Created:** [March 11, 2019, 9:15am UTC](https://discourse.julialang.org/t/how-to-load-a-module-from-the-current-directory/21727 "2019-03-11T09:15:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![HenrikM](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrikm/32/17975_2.png) [@HenrikM](https://discourse.julialang.org/u/HenrikM)\
**Post date:** [March 11, 2019, 9:15am UTC](https://discourse.julialang.org/t/how-to-load-a-module-from-the-current-directory/21727/1 "2019-03-11T09:15:48Z")

</div>

I thought it sufficed to add your current working directory to `LOAD_PATH` to use modules from there, but apparently that is not so. Is the only way to get local code (for small scale dev/testing) to use `include`? I could swear this worked last week…

```julia
julia> versioninfo()
Julia Version 1.1.0
Commit 80516ca (2019-01-21 21:24 UTC)
...

julia> LOAD_PATH
4-element Array{String,1}:
 "@"                                       
 "@v#.#"                                   
 "@stdlib"                                 
 "/l/tests/julia"

julia> pwd()
"/l/tests/julia"

julia> readdir()
31-element Array{String,1}:
...
 "MyMod.jl"              
 "MyMod.jl~"             
...

julia> using MyMod
ERROR: ArgumentError: Package MyMod not found in current path:
- Run `import Pkg; Pkg.add("MyMod")` to install the MyMod package.

Stacktrace:
 [1] require(::Module, ::Symbol) at ./loading.jl:823

julia> 

```

---

<div class="post-metadata">

**Author:** ![improbable22](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/improbable22/32/5464_2.png) [@improbable22](https://discourse.julialang.org/u/improbable22)\
**Post date:** [March 11, 2019, 9:35am UTC](https://discourse.julialang.org/t/how-to-load-a-module-from-the-current-directory/21727/2 "2019-03-11T09:35:11Z")

</div>

I think you need to explicitly `include("MyMod.jl")`, and then possibly `using .MyMod` (since it’s just a module, not a package).

---

<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 11, 2019, 12:44pm UTC](https://discourse.julialang.org/t/how-to-load-a-module-from-the-current-directory/21727/3 "2019-03-11T12:44:58Z")

</div>

That all looks fine to me, and I checked that it works on my machine.

In situations like this, I find it useful to try to isolate the smallest difference between the broken example and a working example. For example, I would sanity check by creating a new, empty folder, creating a trivial file in that folder like:

```julia
# File: MyMod.jl
module MyMod

x = 1

end

```

and then running (in Julia):

```julia
julia> push!(LOAD_PATH, pwd())
4-element Array{String,1}:
 "@"                                    
 "@v#.#"                                
 "@stdlib"                              
 "/my/folder/with/just/that/one/file"

julia> using MyMod
[Info: Precompiling MyMod [top-level]

julia> MyMod.x
1

```

once you have a working example, it will be easier to figure out what the difference is between that and your (currently broken) example.

---

<div class="post-metadata">

**Author:** ![HenrikM](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrikm/32/17975_2.png) [@HenrikM](https://discourse.julialang.org/u/HenrikM)\
**Post date:** [March 11, 2019, 1:20pm UTC](https://discourse.julialang.org/t/how-to-load-a-module-from-the-current-directory/21727/4 "2019-03-11T13:20:52Z")

</div>

Thank you for your answer!

The issue was that I had an empty `Project.toml` file lying around in that one directory. I’m only at the stage of playing around with `Module`s, `Package`s, `Project`s and everything, so I’m breaking things. 😉

Would you or anybody know of a good introduction to the above subjects?

---

<div class="post-metadata">

**Author:** ![marty0801](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marty0801/32/12715_2.png) [@marty0801](https://discourse.julialang.org/u/marty0801)\
**Post date:** [February 13, 2021, 10:32pm UTC](https://discourse.julialang.org/t/how-to-load-a-module-from-the-current-directory/21727/5 "2021-02-13T22:32:36Z")

</div>

Did you ever find the introduction you were looking for? I could really use one too…

---

<div class="post-metadata">

**Author:** ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)\
**Post date:** [February 13, 2021, 11:56pm UTC](https://discourse.julialang.org/t/how-to-load-a-module-from-the-current-directory/21727/6 "2021-02-13T23:56:07Z")

</div>

I don’t think this particular behaviour is documented yet. If it is, it wasn’t visible enough for me to find it: I as well struggled with this issue a few months ago.

### The confusion

In particular, I had to look through Julia’s code to understand that any entry in `LOAD_PATH`, whose directory contains a `Project.toml` file, will be treated as a “project environment” _ **only** _. In other words: having a `Project.toml` file inhibits Julia from using it as a “package repository”.

### An introduction, for now

At the moment, I would suggest you look at some of the posts I have written, starting with the “tips” found here:  
 → [Proper way of organizing code into subpackages - #3 by MA\_Laforge](https://discourse.julialang.org/t/proper-way-of-organizing-code-into-subpackages/52835/3)

I also suggest you read the two posts of mine that directly follow it. I tried my best to give useful insight.

You might also be interested to take a look at the improved package/module documentation (v1.7):  
 → [Modules · The Julia Language](https://docs.julialang.org/en/v1.7-dev/manual/modules/)

Overall though, I think the package/module documentation still needs some improvement (I just haven’t figured out how, exactly).
