# How to add all dependencies of a package to global environment?

**URL:** <https://discourse.julialang.org/t/how-to-add-all-dependencies-of-a-package-to-global-environment/19725>\
**Category:** General Usage\
**Created:** [January 16, 2019, 10:05pm UTC](https://discourse.julialang.org/t/how-to-add-all-dependencies-of-a-package-to-global-environment/19725 "2019-01-16T22:05:22Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [January 16, 2019, 10:05pm UTC](https://discourse.julialang.org/t/how-to-add-all-dependencies-of-a-package-to-global-environment/19725/1 "2019-01-16T22:05:23Z")

</div>

Suppose I have a package `A` which depends on `B` and `C`. If I run `add A`, then `B` and `C` are activate only in `A`’s environment. This means that if I do `using B` or `using C` from the global environment, it will fail. Is there an easy way to add all the dependencies of a given package like `A` to the global environment, in addition to its own environment, so that `using` them then works? Thanks.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [January 16, 2019, 10:07pm UTC](https://discourse.julialang.org/t/how-to-add-all-dependencies-of-a-package-to-global-environment/19725/2 "2019-01-16T22:07:58Z")

</div>

You can do this:

```julia
pkg> add B C

```

Why do you want this?

---

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [January 16, 2019, 10:21pm UTC](https://discourse.julialang.org/t/how-to-add-all-dependencies-of-a-package-to-global-environment/19725/3 "2019-01-16T22:21:06Z")

</div>

Thanks for the suggestion. So, the reason is that I’m making a MyBinder Docker container for an analysis that I’m hoping to pass onto colleagues. There’s a long list of packages useful for this analysis used throughout the notebooks therein, with all these packages listed as dependencies of `A`. I want to add all these packages to the global environment inside the container, so they’re always easily available to my colleagues.

Some solutions I’ve thought of: 1) I considered yours (but then I have to duplicate the package list in `A`’s `Project.toml` as well as in the `add` command 2) copy `A`’s Project.toml to the global environment (but then this environment gets renamed to `A`, which I’m unsure might cause other problems 3) Create a separate `Project.toml` which I use as the global environment inside the container (which I guess I disfavor again since the duplication issue)

I guess another option is to auto-activate `A` inside the container. I suppose there’s not a command line option, I should do this in `startup.jl` ?

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [January 17, 2019, 12:24am UTC](https://discourse.julialang.org/t/how-to-add-all-dependencies-of-a-package-to-global-environment/19725/4 "2019-01-17T00:24:59Z")

</div>

I actually liked the old behavior, where you could add `A`, and then could also just use any of its dependencies.

My use case is mostly that I add [Queryverse.jl](https://github.com/queryverse/Queryverse.jl), which is a meta-package that pulls in everything that belongs to the Queryverse (so quite a lot). But many times I would then prefer to do `using B` rather than `using A`, because loading Queryverse takes a while with the current precompile/package load issues. That of course doesn’t work, and then I have to add all the individual packages manually, which is annoying.

---

<div class="post-metadata">

**Author:** ![00vareladavid](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/00vareladavid/32/23521_2.png) [@00vareladavid](https://discourse.julialang.org/u/00vareladavid)\
**Post date:** [January 17, 2019, 1:37am UTC](https://discourse.julialang.org/t/how-to-add-all-dependencies-of-a-package-to-global-environment/19725/5 "2019-01-17T01:37:01Z")

</div>

Perhaps something like [https://github.com/QuantEcon/InstantiateFromURL.jl](https://github.com/QuantEcon/InstantiateFromURL.jl) is more appropriate for this use case.

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [January 17, 2019, 1:56am UTC](https://discourse.julialang.org/t/how-to-add-all-dependencies-of-a-package-to-global-environment/19725/6 "2019-01-17T01:56:05Z")

</div>

Uh, that seems way too involved for my use case 🙂

---

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [January 17, 2019, 8:50pm UTC](https://discourse.julialang.org/t/how-to-add-all-dependencies-of-a-package-to-global-environment/19725/7 "2019-01-17T20:50:40Z")

</div>

> [@davidanthoff](#):
>
> I actually liked the old behavior, where you could add `A` , and then could also just use any of its dependencies.

I suppose the reason this can’t be the case anymore is because of the ability of Pkg3 to let packages depend on different versions of the same dependency? I wonder if there’s a way to get the best of both worlds, although I admit I can’t really think of a good way…

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [January 17, 2019, 9:17pm UTC](https://discourse.julialang.org/t/how-to-add-all-dependencies-of-a-package-to-global-environment/19725/8 "2019-01-17T21:17:18Z")

</div>

You can always do `using A.B`

---

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [January 17, 2019, 9:44pm UTC](https://discourse.julialang.org/t/how-to-add-all-dependencies-of-a-package-to-global-environment/19725/9 "2019-01-17T21:44:57Z")

</div>

Ha! Hadn’t realized you can do that. That could potentially be good enough for me (maybe not so much for @davidanthoff, since it seems it still has to load `A`)

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [January 17, 2019, 9:56pm UTC](https://discourse.julialang.org/t/how-to-add-all-dependencies-of-a-package-to-global-environment/19725/10 "2019-01-17T21:56:02Z")

</div>

> [@marius311](#):
>
> I suppose the reason this can’t be the case anymore is because of the ability of Pkg3 to let packages depend on different versions of the same dependency?

This is not true. The main reason is that you should not rely on package `A` to make `B` available to you. The fact that `A` depends on `B` is an implementation detail of `A` that you should not rely on. For example, if `A` suddenly drops its `B` dependency this would break your code! Instead, install the packages you depend on, its rather simple actually.

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [January 17, 2019, 10:43pm UTC](https://discourse.julialang.org/t/how-to-add-all-dependencies-of-a-package-to-global-environment/19725/11 "2019-01-17T22:43:50Z")

</div>

> [@fredrikekre](#):
>
> The main reason is that you should not rely on package `A` to make `B` available to you. The fact that `A` depends on `B` is an implementation detail of `A` that you should not rely on. For example, if `A` suddenly drops its `B` dependency this would break your code! Instead, install the packages you depend on, its rather simple actually.

I think that makes sense in packages, but at the REPL I don’t buy this argument.

---

<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:** [January 18, 2019, 7:42am UTC](https://discourse.julialang.org/t/how-to-add-all-dependencies-of-a-package-to-global-environment/19725/12 "2019-01-18T07:42:52Z")

</div>

> [@davidanthoff](#):
>
> but at the REPL I don’t buy this argument.

I am not sure that whether code is evaluated interactively is the relevant distinction here — what should matter is the active project and the environment. Are you proposing that these behave differently?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [January 18, 2019, 11:09am UTC](https://discourse.julialang.org/t/how-to-add-all-dependencies-of-a-package-to-global-environment/19725/13 "2019-01-18T11:09:28Z")

</div>

> [@davidanthoff](#):
>
> I think that makes sense in packages, but at the REPL I don’t buy this argument.

There might also be many dependencies with the same name in the Manifest, `using Foo` would then be ambiguous.

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [January 18, 2019, 9:06pm UTC](https://discourse.julialang.org/t/how-to-add-all-dependencies-of-a-package-to-global-environment/19725/14 "2019-01-18T21:06:06Z")

</div>

> [@Tamas\_Papp](#):
>
> I am not sure that whether code is evaluated interactively is the relevant distinction here — what should matter is the active project and the environment. Are you proposing that these behave differently?

I just know that it is painful in the REPL. I don’t think it would be the end of the world if something like this behaved slightly different in an interactive context.

> [@kristoffer.carlsson](#):
>
> There might also be many dependencies with the same name in the Manifest, `using Foo` would then be ambiguous.

So throw some sort of ambiguity error if that happens, and make it work in the other cases? We already have a similar situation, that if two packages export the same name and one loads both of them with `using`, _then_ there is an error thrown about the name ambiguity, but everything works if it doesn’t happen.

---

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [January 18, 2019, 10:44pm UTC](https://discourse.julialang.org/t/how-to-add-all-dependencies-of-a-package-to-global-environment/19725/15 "2019-01-18T22:44:49Z")

</div>

As a one off:  
Just copy and paste the parts of A’s Project.toml that you want into the Project.toml of the enviroment you care about. (` ~/.julia/environments/v1.0/Project.toml`),  
then run `]resolve`.

---

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [January 18, 2019, 10:49pm UTC](https://discourse.julialang.org/t/how-to-add-all-dependencies-of-a-package-to-global-environment/19725/16 "2019-01-18T22:49:08Z")

</div>

> [@marius311](#):
>
> I guess another option is to auto-activate `A` inside the container. I suppose there’s not a command line option, I should do this in `startup.jl` ?

If you just download `A` to wherever, e.g. `~/demo/A`  
then start julia with `julia --project=~/demo/A`

then this will do this.

Since it is a docker container for a binder it isn’t like you need to worry about the user messing things up

---

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [January 22, 2019, 6:39am UTC](https://discourse.julialang.org/t/how-to-add-all-dependencies-of-a-package-to-global-environment/19725/17 "2019-01-22T06:39:04Z")

</div>

I realize that my request is basically the same as [https://discourse.julialang.org/t/add-all-packages-from-1-0-3-to-1-1](https://discourse.julialang.org/t/add-all-packages-from-1-0-3-to-1-1), which is probably an even more common case. In their case, they want to add all dependencies from the global environment of 1.0 to that of 1.1. In my case its adding all dependencies from a package environment to a global one, but its basically the same thing. Both can accomplished by copying Project.toml entries by hand, but doing so is probably limited to fairly advanced Julia users. Would it not be possible to have a package command that makes this easy for everyone?

Something like ` add-from: add a given package's dependencies to project` ? Then `add-from 1.0` solves the issue in the link above and `add-from A` or `add-from /path/to/A` (if `A` is not already added) solves mine here?

---

<div class="post-metadata">

**Author:** ![epogrebnyak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/epogrebnyak/32/6287_2.png) [@epogrebnyak](https://discourse.julialang.org/u/epogrebnyak)\
**Post date:** [October 31, 2020, 10:05pm UTC](https://discourse.julialang.org/t/how-to-add-all-dependencies-of-a-package-to-global-environment/19725/18 "2020-10-31T22:05:15Z")

</div>

Outside of global environment the answer will be [this](https://stackoverflow.com/questions/56643810/how-to-create-project-in-julia-and-juno/56658333#56658333)?
