# How to export modules / packages locally?

**URL:** <https://discourse.julialang.org/t/how-to-export-modules-packages-locally/86606>\
**Category:** New to Julia\
**Tags:** packages, modules, code-organization\
**Created:** [August 31, 2022, 5:00pm UTC](https://discourse.julialang.org/t/how-to-export-modules-packages-locally/86606 "2022-08-31T17:00:02Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![hamburger](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hamburger/32/31910_2.png) [@hamburger](https://discourse.julialang.org/u/hamburger)\
**Post date:** [August 31, 2022, 5:00pm UTC](https://discourse.julialang.org/t/how-to-export-modules-packages-locally/86606/1 "2022-08-31T17:00:02Z")

</div>

How to export modules / packages locally?

Hello!

I’ve been looking unsuccessfully at how to develop multiple distinct modules locally. My project has three parts:

Two modules: TextManipulation, AstroPhysics  
One Julia script that uses both TextManipulation and AstroPhysics

I’ve been looking at the documentation and got lost, though I’m pretty sure the answer’s there.

My understanding is that I’d have to

1. build the modules, and export them
2. import the built modules to the environment where the script is running

These tasks seem trivial but I’m getting lost. I also don’t want to have them uploaded to the general registry.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [August 31, 2022, 5:49pm UTC](https://discourse.julialang.org/t/how-to-export-modules-packages-locally/86606/2 "2022-08-31T17:49:47Z")

</div>

Welcome. I think you are searching for:

```julia
include("TextManipulation.jl")
using .TextManipulation

include("AstroPhysics.jl")
using .AstroPhysics

```

if not, please give us further details!

---

<div class="post-metadata">

**Author:** ![Ashlin\_Harris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashlin_harris/32/210166_2.png) [@Ashlin\_Harris](https://discourse.julialang.org/u/Ashlin_Harris)\
**Post date:** [August 31, 2022, 6:37pm UTC](https://discourse.julialang.org/t/how-to-export-modules-packages-locally/86606/3 "2022-08-31T18:37:44Z")

</div>

When I develop packages, I use `activate --temp; dev /path/to/MyPackage` in the Pkg REPL, followed by `using MyPackage`. This will create a temporary environment where you’re free to test things, then make the local package available as if you downloaded it from the registry. However, I’ve only ever developed packages with a single module.

---

<div class="post-metadata">

**Author:** ![hamburger](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hamburger/32/31910_2.png) [@hamburger](https://discourse.julialang.org/u/hamburger)\
**Post date:** [August 31, 2022, 6:50pm UTC](https://discourse.julialang.org/t/how-to-export-modules-packages-locally/86606/4 "2022-08-31T18:50:00Z")

</div>

Thanks Imiq! I believe that my set up is different. Each module and script is in a different environment so I can easily reuse.

I came up with this structure where `AstroText.jl` is the script (and each project will have its own environment):

```julia
[hamburger@x julia_projects]$ tree .
.
├── AstroPhysics
│ ├── Project.toml
│ └── src
│ └── AstroPhysics.jl
├── AstroText
│ ├── Project.toml
│ └── src
│ └── AstroText.jl
└── TextManipulation
    ├── Project.toml
    └── src
        └── TextManipulation.jl

```

I came up with this as I’d like to reuse the `AstroPhysics` and `TextManipulation` modules for other totally unrelated projects.

It seems that what you suggest is to have all modules in the same environment (which I’m trying to avoid as it’d hinder code reuse).

---

<div class="post-metadata">

**Author:** ![hamburger](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hamburger/32/31910_2.png) [@hamburger](https://discourse.julialang.org/u/hamburger)\
**Post date:** [August 31, 2022, 6:51pm UTC](https://discourse.julialang.org/t/how-to-export-modules-packages-locally/86606/5 "2022-08-31T18:51:44Z")

</div>

Thanks Ashlin, that may be what I’m looking for.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [August 31, 2022, 7:21pm UTC](https://discourse.julialang.org/t/how-to-export-modules-packages-locally/86606/6 "2022-08-31T19:21:05Z")

</div>

I see, each “module” is a package (just not registered). Then yes, you can `dev` them in the `AstroText` environment. You can also `add` them using:

```julia
Pkg.add(path="/home/leandro/.julia/dev/Package")

```

That will make a copy of the current state of `Package` to be available in the current environment (using `dev` you will track the changes to that package, which may be what you want, or not)

---

<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:** [August 31, 2022, 8:06pm UTC](https://discourse.julialang.org/t/how-to-export-modules-packages-locally/86606/7 "2022-08-31T20:06:07Z")

</div>

Since you already have a fair bit of structure you might consider registering your packages in a registry of your own. The [LocalRegistry](https://github.com/GunnarFarneback/LocalRegistry.jl) package can help you out with that.

---

<div class="post-metadata">

**Author:** ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Post date:** [August 31, 2022, 11:35pm UTC](https://discourse.julialang.org/t/how-to-export-modules-packages-locally/86606/8 "2022-08-31T23:35:39Z")

</div>

> [@Ashlin\_Harris](#):
>
> then make the local package available as if you downloaded it from the registry.

What do you mean here?  
`import` or `using` from temp environment?  
Or repeat the process in project or default environment?

---

<div class="post-metadata">

**Author:** ![Ashlin\_Harris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashlin_harris/32/210166_2.png) [@Ashlin\_Harris](https://discourse.julialang.org/u/Ashlin_Harris)\
**Post date:** [August 31, 2022, 11:53pm UTC](https://discourse.julialang.org/t/how-to-export-modules-packages-locally/86606/9 "2022-08-31T23:53:17Z")

</div>

When you `]develop` a package from a local or remote directory (your own computer, GitHub, etc.), it gets added to your current environment, whatever that may be. At that point, you could make its contents available with `import` or `using`, just the same as you used Pkg.jl to fetch it from the general registry.

I repeat the process every time I want to test the package I’m developing, which is why I use a temporary environment. I suppose you could just run `]develop` once in your default environment if you are working with a stable package that just isn’t available on the general registry.

---

<div class="post-metadata">

**Author:** ![algunion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/algunion/32/51630_2.png) [@algunion](https://discourse.julialang.org/u/algunion)\
**Post date:** [August 31, 2022, 11:57pm UTC](https://discourse.julialang.org/t/how-to-export-modules-packages-locally/86606/10 "2022-08-31T23:57:05Z")

</div>

When working with different environments, I push everything to my private GitHub repo and simply add them as dependencies by `add repourl` (this way I can simply “update” after committing extra work on any of the dependent packages).

Maybe this is not “the way”, but it reduces my cognitive load (by always using the old `add package` method).

---

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [September 1, 2022, 8:01am UTC](https://discourse.julialang.org/t/how-to-export-modules-packages-locally/86606/11 "2022-09-01T08:01:50Z")

</div>

> [@hamburger](#):
>
> ```julia
> [hamburger@x julia_projects]$ tree .
> .
> ├── AstroPhysics
> │ ├── Project.toml
> │ └── src
> │ └── AstroPhysics.jl
> ├── AstroText
> │ ├── Project.toml
> │ └── src
> │ └── AstroText.jl
> └── TextManipulation
> ├── Project.toml
> └── src
> └── TextManipulation.jl
> 
> ```

In case the previous answers suggesting to use `Pkg.dev` weren’t explicit enough, here is what you should be able to do with such a file structure:

```julia
shell$ julia --project=AstroText

       # Declare dependencies to both your libraries
       # using `develop` means that Pkg does not try to manage versions:
       # you'll use your dependences as they are defined by the current state
       # of the julia source files in the given paths
julia> import Pkg
julia> Pkg.develop("path/to/AstroPhysics")
julia> Pkg.develop("path/to/TextManipulation")

```

The commands above should be run once, to populate the `AstroText/Manifest.toml` file with the relevant information. From there, you can use your libraries from your script without any problem:

```julia
shell$ julia --project=AstroText
julia> using AstroPhysics # should work and load sources from the registered path on your filesystem

```
