# Julia recompiling unchanged modules

**URL:** <https://discourse.julialang.org/t/julia-recompiling-unchanged-modules/53252>\
**Category:** General Usage\
**Tags:** precompilation\
**Created:** [January 12, 2021, 8:47pm UTC](https://discourse.julialang.org/t/julia-recompiling-unchanged-modules/53252 "2021-01-12T20:47:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bluesmoon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bluesmoon/32/327_2.png) [@bluesmoon](https://discourse.julialang.org/u/bluesmoon)\
**Post date:** [January 12, 2021, 8:47pm UTC](https://discourse.julialang.org/t/julia-recompiling-unchanged-modules/53252/1 "2021-01-12T20:47:12Z")

</div>

Hi all,

I’m using julia 1.5.3 on Ubuntu.

I have a bunch of modules with dependencies, and a one line script that just has a `using` statement for these modules (no other code in the script).

I first precompile all my modules using this code in a loop:

```julia
using Pkg
Pkg.activate("<module name>")
Pkg.precompile()
Pkg.activate()

```

(I’ve also tried using `Base.compilecache` instead of `Pkg.precompile` with the same results.)

After the precompile, I try to load my one line script into julia:

`julia init-pkgs.jl`

Julia recompiles all the modules again. Subsequent runs of this code do not result in recompiles.

I don’t quite understand why this happens. Is `Pkg.precompile / Base.compilecache` insufficient for compiling the code? Is there anything else I can do ahead of time so that running my script does not cause a recompile?

Thanks,  
Philip

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [January 12, 2021, 9:22pm UTC](https://discourse.julialang.org/t/julia-recompiling-unchanged-modules/53252/2 "2021-01-12T21:22:09Z")

</div>

Hi Philip,

You may be confused about what `Pkg.activate` does. It changes the environment.

You should just call `Pkg.precompile()` in the environment that you want to run the script. This may be your main environment or perhaps a specific one for your script.

My recommendation is to create a specific environment for your script so the results will be reproducible:

1. In Julia, cd to the directory where your script is.
2. Run `Pkg.activate(".")` or `]activate .` to create a new environment in the current directory.
3. Use `Pkg.add` or `]add` to add your dependencies.
4. Run `Pkg.precompile()` to precompile the packages in the current enviornment
5. When running your script, use `julia --project=. your_script_name.jl`. This activates the environment in the current directory and then runs your script.

---

<div class="post-metadata">

**Author:** ![bluesmoon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bluesmoon/32/327_2.png) [@bluesmoon](https://discourse.julialang.org/u/bluesmoon)\
**Post date:** [January 12, 2021, 9:29pm UTC](https://discourse.julialang.org/t/julia-recompiling-unchanged-modules/53252/3 "2021-01-12T21:29:31Z")

</div>

Thanks, I’ll try this.  
I already have an environment for the script with all dependencies set up but I haven’t used `--project` so that may be the issue.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [January 12, 2021, 9:31pm UTC](https://discourse.julialang.org/t/julia-recompiling-unchanged-modules/53252/4 "2021-01-12T21:31:17Z")

</div>

Julia would just use the base environment for your Julia version if you do not specify that from the command line. Good luck.

---

<div class="post-metadata">

**Author:** ![bluesmoon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bluesmoon/32/327_2.png) [@bluesmoon](https://discourse.julialang.org/u/bluesmoon)\
**Post date:** [January 12, 2021, 9:39pm UTC](https://discourse.julialang.org/t/julia-recompiling-unchanged-modules/53252/5 "2021-01-12T21:39:55Z")

</div>

What does `@.` mean and how is it different from `.`?

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [January 12, 2021, 9:59pm UTC](https://discourse.julialang.org/t/julia-recompiling-unchanged-modules/53252/6 "2021-01-12T21:59:05Z")

</div>

From [Getting Started · The Julia Language](https://docs.julialang.org/en/v1/manual/getting-started/)

`--project[={<dir>|@.}]`

Set as the home project/environment. The default @. option will search through parent directories until a Project.toml or JuliaProject.toml file is found.

Also see the following note:

```julia
In Julia 1.0, the default --project=@. option did not search up from the root directory of a Git repository for the Project.toml file. From Julia 1.1 forward, it does.

```
