# Using a dev --local package in module

**URL:** <https://discourse.julialang.org/t/using-a-dev-local-package-in-module/34323>\
**Category:** New to Julia\
**Tags:** package\
**Created:** [February 7, 2020, 9:25pm UTC](https://discourse.julialang.org/t/using-a-dev-local-package-in-module/34323 "2020-02-07T21:25:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ric.cioffi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ric.cioffi/32/18373_2.png) [@ric.cioffi](https://discourse.julialang.org/u/ric.cioffi)\
**Post date:** [February 7, 2020, 9:25pm UTC](https://discourse.julialang.org/t/using-a-dev-local-package-in-module/34323/1 "2020-02-07T21:25:42Z")

</div>

Let’s say I have a module `MyModule` in which I want to use a modified version of a registered package, for instance `DifferentialEquations`. In order not to “pollute” any other environment I can `dev --local DifferentialEquations` from within my module, work on it and add my favorite new functions.

Now, if I simply do `using MyModule` when I start up julia, it will still load the registered version of the package (and not my local dev version). I can get around this by first doing `]activate MyModule` and then `using MyModule`, which then loads my local version of `DifferentialEquations`. However, this is a bit annoying to do with multiple packages and seems like I’m doing something wrong.

(I think this might have to do with the fact that if I do `]activate MyModule; status` then I see the dev version of `DifferentialEquations`, while if I simply do `]status MyModule` from the main environment then I see the registered version of `DifferentialEquations`)

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [February 7, 2020, 9:52pm UTC](https://discourse.julialang.org/t/using-a-dev-local-package-in-module/34323/2 "2020-02-07T21:52:34Z")

</div>

I think that you are actually doing it _right_.

`] activate` is the way to proceed in order to switch environments, such that in one environment you have some packages and in another you have other packages (or other versions of the same ones).

Modules may have their own environments, but you can also have environments for broader projects. If you are using your local dev version of `DifferentialEquations` for multiple modules, you can make an umbrella project that you may use to work with all of them. E.g.:

```julia
cd("MyProject")
] activate .
] dev DifferentialEquations
] dev MyModule
] dev AnotherModule

```

And then, any time you want to work in that project:

```julia
cd("MyProject")
] activate .
using MyModule
using AnotherModule

```

---

<div class="post-metadata">

**Author:** ![ric.cioffi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ric.cioffi/32/18373_2.png) [@ric.cioffi](https://discourse.julialang.org/u/ric.cioffi)\
**Post date:** [February 7, 2020, 11:40pm UTC](https://discourse.julialang.org/t/using-a-dev-local-package-in-module/34323/3 "2020-02-07T23:40:34Z")

</div>

I guess what I’m asking is: why is it the case that `using MyModule` does not load packages from its own environment rather than from the active environment?

Is there a way to avoid having to `activate` a module’s environment before using it?

There should be one, right? Because if I have two different modules that use dev versions of different packages (or different dev versions of the same package) and I need to load these modules into a third module I’d have no way to activate them first.

---

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [February 8, 2020, 7:01am UTC](https://discourse.julialang.org/t/using-a-dev-local-package-in-module/34323/4 "2020-02-08T07:01:52Z")

</div>

Ok, I understand: you mean that you’d expect `MyModule.DifferentialEquations` be the dev version regardless of the environment where you are using MyModule.

Well, I agree with that. I would expect that too.

---

<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:** [February 8, 2020, 8:44am UTC](https://discourse.julialang.org/t/using-a-dev-local-package-in-module/34323/5 "2020-02-08T08:44:47Z")

</div>

Environments stack “upwards”, but not “downwards”: the manifest of the _used_ projects is ignored. See

[https://docs.julialang.org/en/v1/manual/code-loading/](https://docs.julialang.org/en/v1/manual/code-loading/)

For this particular use case, a possible workflow could be

1. making a _non-local_ development branch of `DifferentialEquations`,
2. `dev`ing or `add`ing that in the `MyProject` environment.

---

<div class="post-metadata">

**Author:** ![ric.cioffi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ric.cioffi/32/18373_2.png) [@ric.cioffi](https://discourse.julialang.org/u/ric.cioffi)\
**Post date:** [February 8, 2020, 7:28pm UTC](https://discourse.julialang.org/t/using-a-dev-local-package-in-module/34323/6 "2020-02-08T19:28:27Z")

</div>

I carefully read the docs you linked. As you say it must have to do with the behavior of environment stacks, which is still not totally clear to me.

I find this behavior very counterintuitive: in `MyModule`’s `Project.toml` file `DifferentialEquations` is correctly identified by the UUID of its `dev --local` version and the `Manifest.toml` file points to the correct directory, i.e. `/MyModule/dev/DifferentialEquations`.  
I would therefore expect that `using DifferentialEquations` in `MyModule` would load exactly that version. Instead it loads the version of whatever environment I’m in.

Also, why does a non-local development branch fixes the issue?

I still think there has to be something wrong going on. I’ll make an example to try to convey why:  
Let’s say I have two different modules `MyModule1` and `MyModule2`. In both modules I need to implement a change to `DifferentialEquations`, but they need to be different changes which for whatever reason are incompatible with each other. What I could then do is `dev --local DifferentialEquations` in both modules’ environments which would allow me to add the private features that I need in the correct module. The only thing I need to take care of is to first load the correct environment before using the necessary module, so far so good.

However, let’s now say I need to use both `MyModule1` and `MyModule2` in a `ParentModule` (which can also be the main module). Well now I have a problem, because loading both is going to be impossible, isn’t it?

I know this sounds like a very edge case (and is not actually my use case). I’m just thinking out loud as to why this doesn’t make sense to me.

---

<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:** [February 9, 2020, 7:47am UTC](https://discourse.julialang.org/t/using-a-dev-local-package-in-module/34323/7 "2020-02-09T07:47:04Z")

</div>

> [@ric.cioffi](#):
>
> I would therefore expect that `using DifferentialEquations` in `MyModule` would load exactly that version. Instead it loads the version of whatever environment I’m in.

I think what you are missing is that a Julia image cannot have different versions of the same module loaded.

So if the active project `A` uses `B` which uses `C`, the resolver will figure out the versions given all the _constraints_ in `A` and `B`, which will mean a specific version of `C`, and the manifest of `B` will be ignored.

> [@ric.cioffi](#):
>
> Also, why does a non-local development branch fixes the issue?

So that `A` (in the example above) can find it.

> [@ric.cioffi](#):
>
> Well now I have a problem, because loading both is going to be impossible, isn’t it?

Yes.

> [@ric.cioffi](#):
>
> In both modules I need to implement a change to `DifferentialEquations` , but they need to be different changes which for whatever reason are incompatible with each other.

Your best option is creating a merge of these in yet another branch.

---

<div class="post-metadata">

**Author:** ![ric.cioffi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ric.cioffi/32/18373_2.png) [@ric.cioffi](https://discourse.julialang.org/u/ric.cioffi)\
**Post date:** [February 11, 2020, 1:04am UTC](https://discourse.julialang.org/t/using-a-dev-local-package-in-module/34323/8 "2020-02-11T01:04:24Z")

</div>

Yes, you’re obviously right.

I find this to be a bit of a limit of the package manager, but I’m definitely missing some reason why it was chosen to be this way: I absolutely love everything else of it.

Well I guess I’ll have to live with loading its environment before using the package. Unfortunately the non-local branch solution does not really work as I use the non-dev version in other packages (I’ll mark it as solved anyway, thanks for the replies 🙂).
