# Correct way of passing paths in the REPL for a project containing sub folders

**URL:** <https://discourse.julialang.org/t/correct-way-of-passing-paths-in-the-repl-for-a-project-containing-sub-folders/30380>\
**Category:** New to Julia\
**Created:** [October 27, 2019, 10:19pm UTC](https://discourse.julialang.org/t/correct-way-of-passing-paths-in-the-repl-for-a-project-containing-sub-folders/30380 "2019-10-27T22:19:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![aortizb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aortizb/32/6513_2.png) [@aortizb](https://discourse.julialang.org/u/aortizb)\
**Post date:** [October 27, 2019, 10:19pm UTC](https://discourse.julialang.org/t/correct-way-of-passing-paths-in-the-repl-for-a-project-containing-sub-folders/30380/1 "2019-10-27T22:19:46Z")

</div>

Hi all, I’ve been using Atom for a while and now I am trying to run my codes directly from the REPL without using Atom, that is, I write the \*.jl files using an external text editor and then invoke julia.exe to run the code. My project contains sub folders where \*.jl files reside. When I run this code from the REPL I get some errors because (I think) Julia can’t find the sub folders in the julia path. I’ve prepared a small sample project to show the problem I am facing. I describe it next.

There is a folder named “julia\_test” in the root directory (C:) that contains sub folders and files:  
 ![folders](https://global.discourse-cdn.com/julialang/original/3X/b/9/b9e59ed874c81ba352bb516e86da2bf330d9746e.png)

The \*jl files are the following:

**main.jl**

```julia
include("..\\setpaths.jl")
setpaths()

using VectorOperations: dotproduct

v1 = [1.0,2.0,3.0]
v2 = [2.0,2.0,2.0]

p = dotproduct(v1,v2)

println("v1 * v2 = $p")

```

**setpaths.jl**

```julia
function setpaths()
  rootdir = pwd()
  testdir = joinpath(rootdir,"test")
  sourcedir = joinpath(rootdir,"src")
  sourcedir1 = joinpath(rootdir,"src\\VectorOperations")
  push!(LOAD_PATH, rootdir, testdir, sourcedir, sourcedir1)
end

```

**VectorOperations.jl**

```julia
module VectorOperations

using LinearAlgebra: dot

# VectorOperations functions
include("VectorOperationsFunctions.jl")
export dotproduct

end

```

**VectorOperationsFunctions.jl**

```julia
function dotproduct(v1,v2)
  return dot(v1,v2)
end

```

The file I run is “main.jl”. To this end, I make sure julia.exe is started inside folder “test”:

 ![img1](https://global.discourse-cdn.com/julialang/original/3X/b/c/bc871d1907feefdf5f81e0247a02bd91ee0ab757.png)

Then, in the REPL I execute the following:

```julia
include("main.jl")

```

However, I get the following error:

```julia
julia> include("main.jl")
ERROR: LoadError: ArgumentError: Package VectorOperations not found in current path:
- Run `import Pkg; Pkg.add("VectorOperations")` to install the VectorOperations package.

Stacktrace:
 [1] require(::Module, ::Symbol) at .\loading.jl:823
 [2] include at .\boot.jl:326 [inlined]
 [3] include_relative(::Module, ::String) at .\loading.jl:1038
 [4] include(::Module, ::String) at .\sysimg.jl:29
 [5] include(::String) at .\client.jl:403
 [6] top-level scope at none:0
in expression starting at C:\julia_test\test\main.jl:4

```

This means that Julia can’t find the definition of VectorOperations module that I defined. The folder where this module resides is “source/VectorOperations” and is specified inside function “setpaths”. I suppose Julia can’t find this sub folder. By the way, this code runs without any problems in Atom. Am I missing something?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 28, 2019, 4:50am UTC](https://discourse.julialang.org/t/correct-way-of-passing-paths-in-the-repl-for-a-project-containing-sub-folders/30380/2 "2019-10-28T04:50:35Z")

</div>

In similar situations, I usually include something like

```julia
project_path(parts...) = normpath(joinpath(@ __DIR__ , "..", parts...))

```

in the main module file (eg `src/Foo.jl`). Then in the REPL I can do

```julia
using Foo
include(project_path("setpaths.jl"))

```

etc.

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [October 28, 2019, 12:18pm UTC](https://discourse.julialang.org/t/correct-way-of-passing-paths-in-the-repl-for-a-project-containing-sub-folders/30380/3 "2019-10-28T12:18:04Z")

</div>

> [@Tamas\_Papp](#):
>
> `project_path(parts...) = normpath(joinpath(@ __DIR__ , "..", parts...))`

For the record `joinpath` is redundant here. Documentation PR: [Docstring for one more normpath method. by GunnarFarneback · Pull Request #33700 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/33700).

---

<div class="post-metadata">

**Author:** ![aortizb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aortizb/32/6513_2.png) [@aortizb](https://discourse.julialang.org/u/aortizb)\
**Post date:** [October 28, 2019, 12:26pm UTC](https://discourse.julialang.org/t/correct-way-of-passing-paths-in-the-repl-for-a-project-containing-sub-folders/30380/4 "2019-10-28T12:26:09Z")

</div>

Thanks @Tamas_Papp. I will try that. Anyway, I found what the problem is. LOAD\_PATH is not set correctly after setpaths() is executed. See what I get:

```julia
julia> pwd()                                    
"C:\\julia_test\\test"                          
                                                
julia> include("main.jl")                       
ERROR: LoadError: ArgumentError: Package VectorOperations not found in current path:            
- Run `import Pkg; Pkg.add("VectorOperations")` 
to install the VectorOperations package.        
                                                
Stacktrace:                                     
 [1] require(::Module, ::Symbol) at .\loading.jl:823                                            
 [2] include at .\boot.jl:326 [inlined]         
 [3] include_relative(::Module, ::String) at .\loading.jl:1038                                  
 [4] include(::Module, ::String) at .\sysimg.jl:29                                              
 [5] include(::String) at .\client.jl:403       
 [6] top-level scope at none:0                  
in expression starting at C:\julia_test\test\main.jl:4                                          
                                                
julia> LOAD_PATH                                
7-element Array{String,1}:                      
 "@"                                            
 "@v#.#"                                        
 "@stdlib"                                      
 "C:\\julia_test\\test"                         
 "C:\\julia_test\\test\\test"                   
 "C:\\julia_test\\test\\src"                    
 "C:\\julia_test\\test\\src\\VectorOperations"                                                 

```

There is an extra “test” folder in the path. However, in Atom it is set OK and that is why it works in Atom:

```julia
julia> LOAD_PATH
7-element Array{String,1}:
 "@"
 "@v#.#"
 "@stdlib"
 "C:\\julia_test\\"
 "C:\\julia_test\\test"
 "C:\\julia_test\\src"
 "C:\\julia_test\\src\\VectorOperations"

```

I am trying to figure out why the problem happens in pure REPL and not in Run All Atom button. I will come back if I fix the problem.

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [October 28, 2019, 1:18pm UTC](https://discourse.julialang.org/t/correct-way-of-passing-paths-in-the-repl-for-a-project-containing-sub-folders/30380/5 "2019-10-28T13:18:26Z")

</div>

Clearly Atom runs it with a different working directory than you expect. Just replacing `rootdir = pwd()` with `rootdir = @ __DIR__ ` should make your code insensitive to working directories.

---

<div class="post-metadata">

**Author:** ![aortizb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aortizb/32/6513_2.png) [@aortizb](https://discourse.julialang.org/u/aortizb)\
**Post date:** [October 28, 2019, 1:36pm UTC](https://discourse.julialang.org/t/correct-way-of-passing-paths-in-the-repl-for-a-project-containing-sub-folders/30380/6 "2019-10-28T13:36:20Z")

</div>

Thanks @GunnarFarneback. That solved the issue.
