# Easier way to load package I'm developing?

**URL:** https://discourse.julialang.org/t/easier-way-to-load-package-im-developing/53370
**Category:** New to Julia
**Created:** [January 15, 2021, 3:30am UTC](https://discourse.julialang.org/t/easier-way-to-load-package-im-developing/53370 "2021-01-15T03:30:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Visipi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/visipi/32/21206_2.png) [@Visipi](https://discourse.julialang.org/u/Visipi)
#### Post date: [January 15, 2021, 3:30am UTC](https://discourse.julialang.org/t/easier-way-to-load-package-im-developing/53370/1 "2021-01-15T03:30:46Z")

</div>

Hi, new to Julia.

I have this package I want to develop which for the sake of example we’ll call myPkg. It’s located in ~/.julia/dev/myPkg and I’ve used PkgTemplates.jl to set up properly.

I’m using Juno through Atom to run my Julia code. When I start up the REPL there I verify that I’m in the correct path:

```julia
julia> pwd()
"~/.julia/dev.myPkg"

```

but when I attempt to load my module from the REPL, I get the following error:

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

```

Now I have found a workaround to this by updating LOAD\_PATH:

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

```

And after doing this I’m able to load myPkg. My question is, why wasn’t this possible for me before when I was already in the correct directory? At face value it’s a minor problem but I have the impression I’m misunderstanding fundamental.

---

<div class="post-metadata">

### Author: ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)
#### Post date: [January 15, 2021, 4:01am UTC](https://discourse.julialang.org/t/easier-way-to-load-package-im-developing/53370/2 "2021-01-15T04:01:34Z")

</div>

`using myPkg` traverses traverses through `LOAD_PATH` and searches the folders listed to see if it can find such a package. There are some default paths as you can see, e.g. `"@v#.#"` that tells the pkg system to look into the `Project.toml` file of the `v#.#` environment and see if it can find an entry to your package there. The package system does not consider `pwd()` as a directory where the package could be located by default, so thats why you had to push to `LOAD_PATH`. I don’t think this is really a good approach unless you are familiar with the Julia package/environment system.

There are two alternative ways. First the more canonical way would be to use `dev`.

```julia
(@v1.4) pkg> dev mypkg
Path `/home/affan/.julia/dev/mypkg` exists and looks like the correct package. Using existing path.
  Resolving package versions...
   Updating `~/.julia/environments/v1.4/Project.toml`
  [c6683dd1] + mypkg v0.1.0 [`~/.julia/dev/mypkg`]
   Updating `~/.julia/environments/v1.4/Manifest.toml`
  [c6683dd1] + mypkg v0.1.0 [`~/.julia/dev/mypkg`]

julia> using mypkg
[Info: Precompiling mypkg [c6683dd1-c332-45c4-be08-9497673428c9]

julia>

```

So by `dev`’ing the package, it adds an entry to your `Project.toml` file with the package information (see `] st` to see the `dev`’ed package info). This will let you run `using mypkg` regardless of your `pwd`. Note the entry for the `dev`’ed package is added to the Project file of the currently active environment.

The second way would be to manually include the file that defines the package module.

```julia
include("file_that_defines_mypkg.jl") # often just myPkg.jl 
using .myPkg 

```

---

<div class="post-metadata">

### Author: ![Visipi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/visipi/32/21206_2.png) [@Visipi](https://discourse.julialang.org/u/Visipi)
#### Post date: [January 15, 2021, 4:58am UTC](https://discourse.julialang.org/t/easier-way-to-load-package-im-developing/53370/3 "2021-01-15T04:58:59Z")

</div>

Great answer. Thanks a million!

---

<div class="post-metadata">

### Author: ![thisrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thisrod/32/10642_2.png) [@thisrod](https://discourse.julialang.org/u/thisrod)
#### Post date: [January 15, 2021, 5:27am UTC](https://discourse.julialang.org/t/easier-way-to-load-package-im-developing/53370/4 "2021-01-15T05:27:29Z")

</div>

> [@Visipi](#):
>
> My question is, why wasn’t this possible for me before when I was already in the correct directory?

Because you were in a different directory than your code loader was 😉 This can easily catch you out.

```
julia> using Pkg

julia> Pkg.status()
Status `~/.julia/environments/v1.5/Project.toml`

julia> Base.load_path()
2-element Array{String,1}:
 "/Users/example/.julia/environments/v1.5/Project.toml"
 "/Applications/Julia-1.5.app/Contents/Resources/julia/share/julia/stdlib/v1.5"

```

One solution is:

```
julia> Pkg.activate(pwd())
 Activating environment at `~/.julia/dev/myPkg`

```

Alternatively, run `julia --project` in the package directory. That has the same effect. From now on, `"@"` on the load path refers to `~/.julia/dev/myPkg`.

```
julia> Pkg.status()
Project myPkg v0.1.0
Status `~/.julia/dev/myPkg/Project.toml`
...

julia> Base.load_path()
3-element Array{String,1}:
 "/Users/example/.julia/dev/myPkg/Project.toml"
 "/Users/example/.julia/environments/v1.5/Project.toml"
 "/Applications/Julia-1.5.app/Contents/Resources/julia/share/julia/stdlib/v1.5"

```

The code loader knows where to find the active package, and `using myPkg` will now work.
