# When should I \`activate\`?

**URL:** <https://discourse.julialang.org/t/when-should-i-activate/105581>\
**Category:** New to Julia\
**Created:** [October 30, 2023, 4:39pm UTC](https://discourse.julialang.org/t/when-should-i-activate/105581 "2023-10-30T16:39:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaimera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kaimera/32/49303_2.png) [@kaimera](https://discourse.julialang.org/u/kaimera)\
**Post date:** [October 30, 2023, 4:39pm UTC](https://discourse.julialang.org/t/when-should-i-activate/105581/1 "2023-10-30T16:39:59Z")

</div>

I understand this is a super basic question, but I don’t think I know the correct words to find similar questions that have already answered this.

I’m attempting to make a package, using Revise.jl. I’m following the [cookbook](https://timholy.github.io/Revise.jl/stable/cookbook/#Package-centric-usage). While I _am_ able to get it to work, I’m curious as to why the cookbook doesn’t have to activate the package before calling `using MyPkg` while it seems like it doesn’t work for me until I run `pkg> activate .` at the top level of the package. If I don’t, I get an error:

```julia
ERROR: ArgumentError: Package MyPkg not found in current path.
- Run `import Pkg; Pkg.add("MyPkg") to install the MyPkg package.

```

Can someone explain to me why I have to `activate` while the cookbook does not?

Thank you!

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [October 30, 2023, 4:47pm UTC](https://discourse.julialang.org/t/when-should-i-activate/105581/2 "2023-10-30T16:47:46Z")

</div>

What version of Julia are you using? In newer versions `using MyPkg` will prompt you to install it (thus, I think the omission in those docs). In your case the package would get installed in your main environment, but that is not really recommendable.

If you are developing `MyPkg`, always be sure to be in the environment `MyPkg>`, either by using `activate .` in the folder, or starting julia with `julia --project`. You should do that.

(to `using MyPkg` work directly, the package must be installed _in the active environment_)

---

<div class="post-metadata">

**Author:** ![kaimera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kaimera/32/49303_2.png) [@kaimera](https://discourse.julialang.org/u/kaimera)\
**Post date:** [October 30, 2023, 5:04pm UTC](https://discourse.julialang.org/t/when-should-i-activate/105581/3 "2023-10-30T17:04:59Z")

</div>

I meant to generalize my example from `GPlate` → `MyPkg` but forgot to do it in most places - sorry if this changes the answer. Editing my post.

---

<div class="post-metadata">

**Author:** ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Post date:** [October 30, 2023, 6:22pm UTC](https://discourse.julialang.org/t/when-should-i-activate/105581/4 "2023-10-30T18:22:27Z")

</div>

It looks to me like that tutorial is skipping some steps regarding the environment. Any package you use will ultimately need to be installed (with `add` or `dev`) somewhere in your [environment stack](https://jkrumbiegel.com/pages/2022-08-26-pkg-introduction/#stacked-environments).

# TLDR

To use `MyPkg`, either activate the `MyPkg` environment with `pkg> activate path/to/MyPkg` or activate a different environment that has `MyPkg` installed in it. You can check which packages are installed in your current environment with `pkg> status`.

# Option 1:

Create a new shared environment. Add `MyPkg` and `Revise` to it.

```julia
(@v1.10) pkg> activate @TestMyPkg
  Activating new project at `C:\Users\nboyer.AIP\.julia\environments\TestMyPkg`

(@TestMyPkg) pkg> add Revise
    Updating registry at `C:\Users\nboyer.AIP\.julia\registries\General.toml`

(@TestMyPkg) pkg> dev C:\Users\nboyer.AIP\.julia\dev\MyPackage
   Resolving package versions...

(@TestMyPkg) pkg> status
Status `C:\Users\nboyer.AIP\.julia\environments\TestMyPkg\Project.toml`
  [4b534a9b] MyPackage v0.1.0 `C:\Users\nboyer.AIP\.julia\dev\MyPackage`
  [295af30f] Revise v3.5.7

julia> using Revise, MyPackage
Precompiling MyPackage
  1 dependency successfully precompiled in 2 seconds

julia> # edit MyPackage and test code here

```

# Option 2

Many people choose to install `Revise` and other developer tooling packages into their default environment (e.g. `@v1.10`). Any package installed in your default environment is also available within any other environment. With the default environment set up this way, you can get basically the same functionality as above just by activating your package’s local environment.

```julia
(@v1.10) pkg> add Revise
   Resolving package versions...
  No Changes to `C:\Users\nboyer.AIP\.julia\environments\v1.10\Project.toml`
  No Changes to `C:\Users\nboyer.AIP\.julia\environments\v1.10\Manifest.toml`

(@v1.10) pkg> activate C:\Users\nboyer.AIP\.julia\dev\MyPackage
  Activating project at `C:\Users\nboyer.AIP\.julia\dev\MyPackage`

(MyPackage) pkg> status
Project MyPackage v0.1.0
Status `C:\Users\nboyer.AIP\.julia\dev\MyPackage\Project.toml`
  [37e2e46d] LinearAlgebra

julia> using Revise, MyPackage

julia> # edit MyPackage and test code here

```

---

<div class="post-metadata">

**Author:** ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)\
**Post date:** [October 30, 2023, 8:33pm UTC](https://discourse.julialang.org/t/when-should-i-activate/105581/5 "2023-10-30T20:33:29Z")

</div>

> [@Nathan\_Boyer](#):
>
> Any package installed in your default environment is also available within any other environment.

To clarify, this is true in interactive development (which is generally the only time you’d want Revise loaded, so it makes sense I’m this context). If you need something within your package code, it needs to be added in the package environment.
