# About module importation

**URL:** <https://discourse.julialang.org/t/about-module-importation/127164>\
**Category:** New to Julia\
**Tags:** modules, code-organization\
**Created:** [March 20, 2025, 5:25am UTC](https://discourse.julialang.org/t/about-module-importation/127164 "2025-03-20T05:25:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gesee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gesee/32/217235_2.png) [@Gesee](https://discourse.julialang.org/u/Gesee)\
**Post date:** [March 20, 2025, 5:25am UTC](https://discourse.julialang.org/t/about-module-importation/127164/1 "2025-03-20T05:25:10Z")

</div>

If I have a module A importing a package B and a module C importing the package B, How can do to import the module B only one time so that module A and module C can use it

---

<div class="post-metadata">

**Author:** ![hexaeder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hexaeder/32/24403_2.png) [@hexaeder](https://discourse.julialang.org/u/hexaeder)\
**Post date:** [March 20, 2025, 6:31am UTC](https://discourse.julialang.org/t/about-module-importation/127164/2 "2025-03-20T06:31:54Z")

</div>

Maybe I am not fully getting you question, but if `B` is indeed package (added using Pkg) there is no problem in `using` multiple times. Do you encounter any problems with this?

```julia
module A
    using B
    # code that usese B
end

```

```julia
module C
    using B
    # code that usese B
end

```

If all `A`, `B` and `C` are modules in files it is a bit more complicated, but it would look roughly like this:

```julia
module MainWorkingModule
    module B
        # define stuff
    end
    module A
        using ..B # i.e. use the module B known in the parent scope of A
        # code that usese B
    end
    module C
        using ..B
        # code that usese B
    end
end

```

naturaly, you can split it up in different files:

```julia
module MainWorkingModule
    include("B.jl")
    include("A.jl")
    include("C.jl")
end

```

Note that `MainWorkingModule` could be also just `Main`, i.e. the repl context.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [March 20, 2025, 7:42am UTC](https://discourse.julialang.org/t/about-module-importation/127164/3 "2025-03-20T07:42:35Z")

</div>

OP probably believes that every import loads the module’s code separately. As you demonstrate, repeated imports actually reuse a loaded module.

---

<div class="post-metadata">

**Author:** ![Gesee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gesee/32/217235_2.png) [@Gesee](https://discourse.julialang.org/u/Gesee)\
**Post date:** [March 20, 2025, 3:51pm UTC](https://discourse.julialang.org/t/about-module-importation/127164/4 "2025-03-20T15:51:12Z")

</div>

In fact I have a module A that import SimpleDirectMediaLayer, but there is also another separate module that need the same package. Since importing SimpleDirectMediaLayer takes some time, I feared that importing it many times will cause trouble

---

<div class="post-metadata">

**Author:** ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)\
**Post date:** [March 20, 2025, 6:39pm UTC](https://discourse.julialang.org/t/about-module-importation/127164/5 "2025-03-20T18:39:15Z")

</div>

> [@Gesee](#):
>
> I feared that importing it many times will cause trouble

Importing a package multiple times only actually loads it once, and subsequent times the already-imported module gets reused.

---

<div class="post-metadata">

**Author:** ![Gesee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gesee/32/217235_2.png) [@Gesee](https://discourse.julialang.org/u/Gesee)\
**Post date:** [March 20, 2025, 10:40pm UTC](https://discourse.julialang.org/t/about-module-importation/127164/6 "2025-03-20T22:40:17Z")

</div>

Thanks
