# Global environment affecting local environment

**URL:** https://discourse.julialang.org/t/global-environment-affecting-local-environment/82611
**Category:** General Usage
**Tags:** package, pkg
**Created:** [June 12, 2022, 12:16am UTC](https://discourse.julialang.org/t/global-environment-affecting-local-environment/82611 "2022-06-12T00:16:45Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![tictaccat](https://avatars.discourse-cdn.com/v4/letter/t/9f8e36/32.png) [@tictaccat](https://discourse.julialang.org/u/tictaccat)
#### Post date: [June 12, 2022, 12:16am UTC](https://discourse.julialang.org/t/global-environment-affecting-local-environment/82611/1 "2022-06-12T00:16:45Z")

</div>

I just ran `julia --project` in my locally developed package with only a few dependencies, and then ran `Pkg.test()`. However, for some reason, the package manager spends a bunch of time precompiling packages like `Plots`, and does this everytime I run tests.

`Plots` is not in `Project.toml` or `Manifest.toml` for my package’s environment. However, I noticed it was in my global environment, and it seems like the global environment’s packages remain active even when I activate a local environment. Is this behaviour expected, and how can I disable it?

---

<div class="post-metadata">

### Author: ![dilumaluthge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dilumaluthge/32/29283_2.png) [@dilumaluthge](https://discourse.julialang.org/u/dilumaluthge)
#### Post date: [June 12, 2022, 12:46am UTC](https://discourse.julialang.org/t/global-environment-affecting-local-environment/82611/2 "2022-06-12T00:46:07Z")

</div>

You can set the `JULIA_LOAD_PATH` environment variable to `@` before you start Julia.

For example, in Bash:

```julia
export JULIA_LOAD_PATH="@"
julia myscript.jl

```

I’m not sure of the corresponding syntax for PowerShell on Windows.

---

<div class="post-metadata">

### Author: ![tictaccat](https://avatars.discourse-cdn.com/v4/letter/t/9f8e36/32.png) [@tictaccat](https://discourse.julialang.org/u/tictaccat)
#### Post date: [June 12, 2022, 1:13am UTC](https://discourse.julialang.org/t/global-environment-affecting-local-environment/82611/3 "2022-06-12T01:13:53Z")

</div>

Got it. I feel like there should be an easier way to do this, like a script option, as the current state of affairs basically means that every local run of scripts or `Pkg.test` is affected by a potentially non-empty global environment, which could affect not just precompilation times but also correctness. (I understand why it’s useful for things like `Revise`.)

---

<div class="post-metadata">

### Author: ![ianshmean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ianshmean/32/216042_2.png) [@ianshmean](https://discourse.julialang.org/u/ianshmean)
#### Post date: [June 12, 2022, 2:29am UTC](https://discourse.julialang.org/t/global-environment-affecting-local-environment/82611/4 "2022-06-12T02:29:53Z")

</div>

I can’t reproduce the issue

```julia
% JULIA_DEPOT_PATH="/tmp/214214" julia         
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.7.2 (2022-02-06)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

(v1.7) pkg> st
      Status `/private/tmp/214214/environments/v1.7/Project.toml`
  [91a5bcdd] Plots v1.29.1

julia> exit()

```

```julia
ian@ians-mbp CSV % JULIA_DEPOT_PATH="/tmp/214214" julia --project

shell> rm -rf /tmp/214214/compiled/v1.7/Plots

(CSV) pkg> test
     Testing CSV
      Status `/private/var/folders/_6/1yf6sj0950vcg4t91m9ltb5w0000gn/T/jl_M1Ip6M/Project.toml`
  [336ed68f] CSV v0.10.4 `/private/tmp/214214/dev/CSV`
  [944b1d66] CodecZlib v0.7.0
  ...
      Status `/private/var/folders/_6/1yf6sj0950vcg4t91m9ltb5w0000gn/T/jl_M1Ip6M/Manifest.toml`
  [336ed68f] CSV v0.10.4 `/private/tmp/214214/dev/CSV`
  ...
     Testing Running tests...

```

`Pkg.test()` did no precompilation. If I understand your issue, the above should be a MWE?

---

<div class="post-metadata">

### Author: ![tictaccat](https://avatars.discourse-cdn.com/v4/letter/t/9f8e36/32.png) [@tictaccat](https://discourse.julialang.org/u/tictaccat)
#### Post date: [June 12, 2022, 5:26am UTC](https://discourse.julialang.org/t/global-environment-affecting-local-environment/82611/5 "2022-06-12T05:26:23Z")

</div>

Right. My test script was actually activating another environment that imported `Plots`, which was the true cause of the precompilation, so that was my bad.

I still think it would be nice to have an easy way to not include the global environment – or at least further emphasize to users that the global environment should be treated with extreme care as it is included by default everywhere. (It’s also super easy to pollute the global environment: just forget to activate your local environment.)

Intuitively, based on the docs I’ve read so far on environments, I thought of the global environment with its `Project.toml` as just another environment. It feels very unintuitive that I can do `using Plots` in `julia --project` in the above example, even though `Plots` is not returned by `] st`.

---

<div class="post-metadata">

### Author: ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)
#### Post date: [June 12, 2022, 8:54am UTC](https://discourse.julialang.org/t/global-environment-affecting-local-environment/82611/6 "2022-06-12T08:54:05Z")

</div>

Yep, I agree. In particular with the point that it is to easy to pollute the global environment. IMO the default environment shouldn’t be the one that is global in the sense of being automatically stacked on top of local environments.

(I also think that stacking should be opt-in.)

Note however that this has been raised a few times before and, unfortunately, hasn’t led to a change. Maybe it’s just because no one went ahead and created a PR. Maybe it’s because there is no consensus. Don’t know.

---

<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: [June 12, 2022, 9:03am UTC](https://discourse.julialang.org/t/global-environment-affecting-local-environment/82611/7 "2022-06-12T09:03:22Z")

</div>

> [@carstenbauer](#):
>
> Maybe it’s because there is no consensus. Don’t know.

That mostly. One if these discussions led to this small package aiming a more practical and less intrusive prototyping: [GitHub - feanor12/Draft.jl: A small package to automatically create temporary environments in offline mode.](https://github.com/feanor12/Draft.jl)

The idea is to start Julia in a temporary environment which can nevertheless be saved, and use in practical way locally available packages. (and with that keep the global environment mostly clean).
