# Pkg.add'ing my own modules Question

**URL:** <https://discourse.julialang.org/t/pkg-adding-my-own-modules-question/1289>\
**Category:** New to Julia\
**Tags:** question, package\
**Created:** [January 4, 2017, 6:53pm UTC](https://discourse.julialang.org/t/pkg-adding-my-own-modules-question/1289 "2017-01-04T18:53:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![peter.mancini](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peter.mancini/32/334_2.png) [@peter.mancini](https://discourse.julialang.org/u/peter.mancini)\
**Post date:** [January 4, 2017, 6:53pm UTC](https://discourse.julialang.org/t/pkg-adding-my-own-modules-question/1289/1 "2017-01-04T18:53:48Z")

</div>

I am at the point where I feel comfortable using the language and now have a project that will be broken up over several modules. I have had trouble adding my own module though. I followed what was written here: [Introducing Julia/Modules and packages - Wikibooks, open books for an open world](https://en.wikibooks.org/wiki/Introducing_Julia/Modules_and_packages)

I have a projects directory and under it are (simplified):

```julia
/projects
  /module1.jl
    /src
      module1.jl
  /module2.jl
    /src
      module2.jl

```

for each module directory I did git init.

I did push!(LOAD\_PATH, “/projects”)

Pkg.add(“module1.jl”) however produces ERROR: unknown package VGTRNG

Have I missed a step or done a step incorrectly? Neither module has a /tests directory yet. Is that an issue? Am I misunderstanding where Pkg.add() will look for packages and I need to do something else to add local packages? Do I need to modify the .git/description?

---

<div class="post-metadata">

**Author:** ![Pbellive](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pbellive/32/3604_2.png) [@Pbellive](https://discourse.julialang.org/u/Pbellive)\
**Post date:** [January 4, 2017, 7:39pm UTC](https://discourse.julialang.org/t/pkg-adding-my-own-modules-question/1289/2 "2017-01-04T19:39:58Z")

</div>

Hi Peter,  
I think you might be confusing modules and packages. Very broadly speaking modules are a way of organizing your code and separating namespaces, whereas packages provide a way to share your code and have users install it easily. See the [documentation on modules](http://docs.julialang.org/en/stable/manual/modules/) for more information on modules.

As far as I know, the `push!(LOAD_PATH, "/projects")` command doesn’t have anything to do with packages. It’s used to add to the list of directories that Julia will search for code. If you want to use statements like

```julia
using module1

```

or

```julia
import module1

```

in your code to brings functions from module1 into scope, you’ll need to tell Julia where to find module1, which in this case is done by appending the “/projects” directory to the `LOAD_PATH` array.

The `Pkg.Add()` command is used to install a registered Julia package. If you want to create your own package from scratch, your first step is to run the `Pkg.generate("package-name",license)` function in Julia. That command will create a folder called “package-name” in your .julia directory. The “package-name” folder will contain a git repository with some boilerplate code and directory structure for creating a package. See [here](http://docs.julialang.org/en/stable/manual/packages/#generating-the-package) in the documentation for more information. Note that your .julia directory is searched for code by default so if you were to generate a module1 package and move your code into the .julia directory there’s no need to add to the LOAD\_PATH in order for julia to be able to find the code.

Finally, packages really start to be useful when you want to share your code with others but as far as I can tell, there’s no harm in using them even if your code is just for you.

---

<div class="post-metadata">

**Author:** ![peter.mancini](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peter.mancini/32/334_2.png) [@peter.mancini](https://discourse.julialang.org/u/peter.mancini)\
**Post date:** [January 4, 2017, 9:07pm UTC](https://discourse.julialang.org/t/pkg-adding-my-own-modules-question/1289/3 "2017-01-04T21:07:07Z")

</div>

That is great. Thanks for helping me understand the distinction. The code I am writing is important for my team at work, so I want to share it in an easy manner. I suppose making it available in a local git repo and then making sure my team adds the directory holding these modules to the LOAD\_PATH is the right thing for now.

The Pkg.generate function looks like it will be useful in the long run. Thank you so much for the help.

–Pete

---

<div class="post-metadata">

**Author:** ![Daneel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daneel/32/175_2.png) [@Daneel](https://discourse.julialang.org/u/Daneel)\
**Post date:** [January 5, 2017, 7:28am UTC](https://discourse.julialang.org/t/pkg-adding-my-own-modules-question/1289/4 "2017-01-05T07:28:59Z")

</div>

Just to be clear, `Pkg.add` is only good for _registered_ packages so if you don’t want to publish your code publicly you’ll have to use `Pkg.clone` and `Pkg.checkout` to initially copy the code and update it.

---

<div class="post-metadata">

**Author:** ![stustd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stustd/32/21430_2.png) [@stustd](https://discourse.julialang.org/u/stustd)\
**Post date:** [January 5, 2017, 10:45am UTC](https://discourse.julialang.org/t/pkg-adding-my-own-modules-question/1289/5 "2017-01-05T10:45:18Z")

</div>

Slightly topic related, since `using SomePkg` doesn’t allow for its modules (under the pkg’s directory tree) to mutually refer to (i.e. use) between each other (…the so-called _circular dependency problem_), I wrote a little module that allows one do so (i.e. bypassing `using Pkg`). See:

[https://github.com/stustd/julia-intra-package-module-usage](https://github.com/stustd/julia-intra-package-module-usage)
