# Understanding environments and DrWatson

**URL:** <https://discourse.julialang.org/t/understanding-environments-and-drwatson/41294>\
**Category:** General Usage\
**Created:** [June 12, 2020, 7:43pm UTC](https://discourse.julialang.org/t/understanding-environments-and-drwatson/41294 "2020-06-12T19:43:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [June 12, 2020, 7:43pm UTC](https://discourse.julialang.org/t/understanding-environments-and-drwatson/41294/1 "2020-06-12T19:43:34Z")

</div>

Suppose I have a package that looks like this

```julia
module MyPkg
   using Distributions, DataFrames
   function a() end
end

```

There is an associated environment with this that has `Project.toml.Manifest.toml` files that tell `MyPkg` exactly what version of `Distributions` and `DataFrames` to use.

Now suppose I created a `DrWatson.jl` project. By doing this, DrWatson has set up a project directory for me with relevant folders and also created a `Project.toml/Manifest.toml` files, and activated it. For clarity, let’s say this project is called `contact_tracing` and my prompt now looks like this: `(contact_tracing) pkg>`.

Now they suggest to add my my package, so basically `(contact_tracing) pkg> add MyPkg` and then in my script file I have `using MyPkg`.

So my question is, when I type in `using MyPkg`, what versions of `Distributions` and `DataFrames` is going to get pulled? The latest ones tagged ones? Because that’s not what I want. I’ve already specified in the package `Project.toml` which particular version I want, so it should be able to get that right?

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [June 12, 2020, 8:01pm UTC](https://discourse.julialang.org/t/understanding-environments-and-drwatson/41294/2 "2020-06-12T20:01:37Z")

</div>

Don’t edit the `Project.toml` directly.

Use `add DataFrames@version_numer` to add a particular package version you want.

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [June 12, 2020, 8:03pm UTC](https://discourse.julialang.org/t/understanding-environments-and-drwatson/41294/3 "2020-06-12T20:03:24Z")

</div>

MyPkg should give bounds on the versions of its dependencies. Now when another package installs it, it will try to install the latest possible version of the dependncies. To choose a particular one, do as @pdeffebach wrote. You can then also `pin` a package, which means that if you later do an update, it will not update.

---

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [June 12, 2020, 8:12pm UTC](https://discourse.julialang.org/t/understanding-environments-and-drwatson/41294/4 "2020-06-12T20:12:24Z")

</div>

This dosn’t really work. Let’s go through an entire example. I have a brand new package called `mypkg`. I add an older dependency of DataFrames to this (current version is 0.21)

```julia
(mypkg) pkg> add DataFrames#v0.20.2
  Resolving package versions...
   Updating `~/.julia/dev/mypkg/Project.toml`
  [a93c6f00] + DataFrames v0.20.2 #v0.20.2 (https://github.com/JuliaData/DataFrames.jl.git)

```

I know that now when I type in `using mypkg` it will use v0.20.2 (as long as the environment is activated).

Now I create a DrWatson project. Lets called it `my_science_project`. The science project uses the package `mypkg` defined above, and so we will add that in a few steps. First, lets initialize (from global environment)

```julia
julia> using DrWatson
julia> initialize_project(".")
 Activating new environment at `~/my_sci_project/Project.toml`
   Updating registry at `~/.julia/registries/General`
   Updating git-repo `https://github.com/JuliaRegistries/General.git`
  Resolving package versions...
   Updating `~/my_sci_project/Project.toml`
  [634d3b9d] + DrWatson v1.13.1

```

Great. Now let’s activate this project and verify the environment has changed.

```julia
julia> quickactivate(".") ## could also use Pkg.activate
 Activating environment at `~/my_sci_project/Project.toml`

(my_sci_project) pkg>

```

I am going to add my dependency now (note: I have to use `dev` here since the folder exists in my julia dev path)

```julia
(my_sci_project) pkg> dev mypkg
Path `/home/affans/.julia/dev/mypkg` exists and looks like the correct package. Using existing path.
  Resolving package versions...
   Updating `~/my_sci_project/Project.toml`
  [08773ad6] + mypkg v0.1.0 [`~/.julia/dev/mypkg`]
   Updating `~/my_sci_project/Manifest.toml`
  [324d7699] + CategoricalArrays v0.8.1
  [34da2185] + Compat v3.12.0
  [9a962f9c] + DataAPI v1.3.0
  [a93c6f00] + DataFrames v0.21.2

```

We see that it added version 0.21.2 (the latest version) for DataFrames in the Manifest? This is not what I want. The functions inside will break if using v0.21.2 and only work with v0.20.2. How can I force this dependency?

I don’t expect my end users to manually look at the Project file of my package and then add that in manually in their drwatson projects.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [June 12, 2020, 8:19pm UTC](https://discourse.julialang.org/t/understanding-environments-and-drwatson/41294/5 "2020-06-12T20:19:27Z")

</div>

I think this is solved if you `pin` DataFrames in `mypkg`, not just add a version, sorry.

btw, what functions are broken on DataFrames? Perhaps we can help you update those parts of your code.

---

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [June 12, 2020, 8:20pm UTC](https://discourse.julialang.org/t/understanding-environments-and-drwatson/41294/6 "2020-06-12T20:20:46Z")

</div>

Oh I see. I will try pinning the package. I thin alternatively, I have to use `[compat]` from reading the documentation.

There is nothing special about DataFrames and I was just using it as an example to explain what I was trying to do.

Edit: Yes, so adding `compat` worked. I havn’t tried pinning but that may also work as well.
