# How to ship the exact environment together with a julia script

**URL:** <https://discourse.julialang.org/t/how-to-ship-the-exact-environment-together-with-a-julia-script/48199>\
**Category:** General Usage\
**Created:** [October 12, 2020, 8:32am UTC](https://discourse.julialang.org/t/how-to-ship-the-exact-environment-together-with-a-julia-script/48199 "2020-10-12T08:32:30Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [October 12, 2020, 8:32am UTC](https://discourse.julialang.org/t/how-to-ship-the-exact-environment-together-with-a-julia-script/48199/1 "2020-10-12T08:32:30Z")

</div>

I did come across with the dependency hell for a Pyton script I wrote 4-5 years ago whose output was finally to get published.  
I need to run however my script under a slightly changed scenario and when I try to blindly press run on each cell of a Python notebook… BOOM !! I come to the problem of dependencies that changed their API and I have now to spend time to look at my old code in detail, look how to update it etc, all in order to change a single parameter of a function.

Now, to be fair, I think also in Python there must be ways to solve this problem, but I now switched to Julia 🙂 🙂 :-).

Which is the proper way to “ship” a project (that can be a simple script) with the exact version of its dependencies ? `]activate .` on the folder , `].add` the various dependencies and then ship the folder with the script and the two files `Project.toml` and `Manifest.toml` ?

What will it happens when I will try to run the script on a machine with more up to date packages ? Will it try to update the dependant libraries automatically?

And what if the machine has a newer version of Julia? I did notice that both `Project.toml` and `Manifest.toml` do not contain any information on the _Julia base_ version.

---

<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:** [October 12, 2020, 8:47am UTC](https://discourse.julialang.org/t/how-to-ship-the-exact-environment-together-with-a-julia-script/48199/2 "2020-10-12T08:47:47Z")

</div>

> [@sylvaticus](#):
>
> Which is the proper way to “ship” a project (that can be a simple script) with the exact version of its dependencies ? `]activate .` on the folder , `].add` the various dependencies and then ship the folder with the script and the two files `Project.toml` and `Manifest.toml` ?

Yes, this is the way to do it. You need to be observant that you don’t depend on anything in your global environment though, preferably by removing it from your load path.

> [@sylvaticus](#):
>
> What will it happens when I will try to run the script on a machine with more up to date packages ? Will it try to update the dependant libraries automatically?

No, it will only update versions of dependencies if you run `Pkg.update`, so don’t do that. You may need to `Pkg.instantiate()` though to make all the packages available in the right versions and it’s a good idea to start your script with that.

> [@sylvaticus](#):
>
> And what if the machine has a newer version of Julia? I did notice that both `Project.toml` and `Manifest.toml` do not contain any information on the _Julia base_ version.

Yes, this is a known weakness. If you can instantiate on a newer version of Julia with the same major version you should be good to go but otherwise you need to run an older version of Julia. It’s a good idea to document which version of Julia was used originally.  
Edit: This doesn’t sound right. Updating to a higher minor version should be fine but going to an older version can certainly be problematic, so it’s at least a good idea to document the used version for that reason.

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [October 12, 2020, 9:08am UTC](https://discourse.julialang.org/t/how-to-ship-the-exact-environment-together-with-a-julia-script/48199/3 "2020-10-12T09:08:57Z")

</div>

> [@GunnarFarneback](#):
>
> You need to be observant that you don’t depend on anything in your global environment though, preferably by removing it from your load path.

How do I do that (be sure that if I use some package that’s has been included in the local Project/Manifest file) ?

---

<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:** [October 12, 2020, 9:41am UTC](https://discourse.julialang.org/t/how-to-ship-the-exact-environment-together-with-a-julia-script/48199/4 "2020-10-12T09:41:58Z")

</div>

See [How to install packages which are needed only for development - #2 by fredrikekre](https://discourse.julialang.org/t/how-to-install-packages-which-are-needed-only-for-development/21815/2) for a related discussion. In contrast to that case you most likely want to keep `@stdlib` though.

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [October 12, 2020, 10:17am UTC](https://discourse.julialang.org/t/how-to-ship-the-exact-environment-together-with-a-julia-script/48199/5 "2020-10-12T10:17:43Z")

</div>

I see. It would have been nice if there was a way to “force” it from Julia itself rather than using env variables, something like `Pkg.envpaths(["."])`

---

<div class="post-metadata">

**Author:** ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)\
**Post date:** [October 12, 2020, 10:29am UTC](https://discourse.julialang.org/t/how-to-ship-the-exact-environment-together-with-a-julia-script/48199/6 "2020-10-12T10:29:02Z")

</div>

You can do it from within Julia, you just manipulate the global variable `LOAD_PATH`. See e.g. [Creating empty isolated environment - #5 by fredrikekre](https://discourse.julialang.org/t/creating-empty-isolated-environment/22183/5)

---

<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:** [October 12, 2020, 10:41am UTC](https://discourse.julialang.org/t/how-to-ship-the-exact-environment-together-with-a-julia-script/48199/7 "2020-10-12T10:41:13Z")

</div>

Haha, seems I got lost in my searches. That was what I had intended to link to.

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [October 12, 2020, 10:55am UTC](https://discourse.julialang.org/t/how-to-ship-the-exact-environment-together-with-a-julia-script/48199/8 "2020-10-12T10:55:39Z")

</div>

I think I finally got it.  
for example on a project where I need DataFrames:

Only once:

```julia
cd(@ __DIR__ )
using Pkg
Pkg.activate(".")
Pkg.add("DataFrames")
# .. add the other package needed...

```

In myProject.jl

```julia
# This script works on julia 1.5
cd(@ __DIR__ )
using Pkg
push!(empty!(LOAD_PATH), ".")
Pkg.activate(".")
Pkg.instantiate()

using DataFrames # Ok, in local {Project|Manifest}.toml as it has been specifically added
a = DataFrame(a =[1,2,3], b=["aaa","bbb","ccc"])
using Flux # In global, but not in local toml files, it will (correctly) rise an error

```

Ship:  
⤑ the folder with `myProject.jl`, `Project.toml` and `Manifest.toml`

---

<div class="post-metadata">

**Author:** ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)\
**Post date:** [October 12, 2020, 11:18am UTC](https://discourse.julialang.org/t/how-to-ship-the-exact-environment-together-with-a-julia-script/48199/9 "2020-10-12T11:18:57Z")

</div>

Looks about right to me!

> [@sylvaticus](#):
>
> Only once:
> 
> ```julia
> cd(@ __DIR__ )
> using Pkg
> Pkg.activate(".")
> Pkg.add("DataFrames")
> # .. add the other package needed...
> 
> ```

You can also just use the package REPL mode (type `]` to enter the mode, then `add DataFrames` etc), instead of a separate script.

> [@sylvaticus](#):
>
> ```julia
> empty!(LOAD_PATH) # This rise an error in Juno, it seems without consequences
> push!(LOAD_PATH, ".")
> 
> ```

You can do this in one line, which maybe Juno would like better? `push!(empty!(LOAD_PATH), ".")`

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [October 12, 2020, 11:24am UTC](https://discourse.julialang.org/t/how-to-ship-the-exact-environment-together-with-a-julia-script/48199/10 "2020-10-12T11:24:02Z")

</div>

correct, edited my post above…

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 12, 2020, 11:36am UTC](https://discourse.julialang.org/t/how-to-ship-the-exact-environment-together-with-a-julia-script/48199/11 "2020-10-12T11:36:32Z")

</div>

> [@sylvaticus](#):
>
> And what if the machine has a newer version of Julia? I did notice that both `Project.toml` and `Manifest.toml` do not contain any information on the _Julia base_ version.

You can (and should) include a `[compat]` entry for `julia`, too.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [October 12, 2020, 12:07pm UTC](https://discourse.julialang.org/t/how-to-ship-the-exact-environment-together-with-a-julia-script/48199/12 "2020-10-12T12:07:55Z")

</div>

To add on to what @Tamas_Papp wrote, you can find the [documentation about compatibility](https://julialang.github.io/Pkg.jl/v1/compatibility/) in the docs of Pkg (linked from the documentation of julia).

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [October 12, 2020, 12:25pm UTC](https://discourse.julialang.org/t/how-to-ship-the-exact-environment-together-with-a-julia-script/48199/13 "2020-10-12T12:25:13Z")

</div>

What is the effect of adding Julia in the compat section ?

I did add

```julia
[compat]
julia = "2.6.0"

```

or even

```julia
[compat]
julia = "= 2.6.0"

```

but the script still runs without giving any warning… (no, I don’t have Julia 2.6 installed 🙃 🙃)

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 12, 2020, 12:36pm UTC](https://discourse.julialang.org/t/how-to-ship-the-exact-environment-together-with-a-julia-script/48199/14 "2020-10-12T12:36:17Z")

</div>

On `master`, you should get a warning along the lines of

```julia
[ Warning: julia version requirement for project not satisfied

```

when you instantiate. I imagine this will be dealt with more strictly when 2.0 is released.

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [October 12, 2020, 12:47pm UTC](https://discourse.julialang.org/t/how-to-ship-the-exact-environment-together-with-a-julia-script/48199/15 "2020-10-12T12:47:42Z")

</div>

ok, thank you for the info (I don’t have the warning with Julia 1.5.0)
