# Initialize a package

**URL:** <https://discourse.julialang.org/t/initialize-a-package/111662>\
**Category:** General Usage\
**Tags:** question\
**Created:** [March 15, 2024, 1:29pm UTC](https://discourse.julialang.org/t/initialize-a-package/111662 "2024-03-15T13:29:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [March 15, 2024, 1:29pm UTC](https://discourse.julialang.org/t/initialize-a-package/111662/1 "2024-03-15T13:29:30Z")

</div>

I have a package that needs some configuration data. Example data that is needed for tests is included in the package. But when I load the package the data path shall be set to `joinpath(pwd(), "data")`.

Where could I call a function that sets this path correctly when loading the package?

In the moment it is always set to:

```julia
julia> get_data_path()
"/home/ufechner/.julia/packages/KiteUtils/85Gnv/data"

```

which is correct when testing the package, but wrong when using it…

---

<div class="post-metadata">

**Author:** ![sbuercklin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sbuercklin/32/15728_2.png) [@sbuercklin](https://discourse.julialang.org/u/sbuercklin)\
**Post date:** [March 15, 2024, 1:43pm UTC](https://discourse.julialang.org/t/initialize-a-package/111662/2 "2024-03-15T13:43:28Z")

</div>

Using a random package from my default environment:

```julia
julia> using JSON3

julia> pkgdir(JSON3, "data")
"/home/sbuercklin/.julia/packages/JSON3/jSAdy/data"

```

You can use `pkgdir` to get the proper directory to point to the `data` directory. This also works from within the `module` defining your package.

Other useful tools here could be `@ __FILE__ ` and `@ __DIR__ ` which expand to the file and directory where the code lives, respectively

---

<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:** [March 15, 2024, 1:55pm UTC](https://discourse.julialang.org/t/initialize-a-package/111662/3 "2024-03-15T13:55:09Z")

</div>

The only place you can do that is in the ` __init__ ()` function of the package module.

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [March 15, 2024, 2:53pm UTC](https://discourse.julialang.org/t/initialize-a-package/111662/4 "2024-03-15T14:53:59Z")

</div>

Other options for data dependencies include:

- [GitHub - oxinabox/DataDeps.jl: reproducible data setup for reproducible science](https://github.com/oxinabox/DataDeps.jl)
- [GitHub - tecosaur/DataToolkit.jl: Reproducible, flexible, and convenient data management](https://github.com/tecosaur/DataToolkit.jl)

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [March 15, 2024, 2:55pm UTC](https://discourse.julialang.org/t/initialize-a-package/111662/5 "2024-03-15T14:55:29Z")

</div>

This works:

```julia
function __init__ ()
    set_data_path(joinpath(pwd(), "data"))
end

```

Thank you!
