# Understanding \`@everywhere\` and environments

**URL:** <https://discourse.julialang.org/t/understanding-everywhere-and-environments/27438>\
**Category:** General Usage\
**Created:** [August 12, 2019, 1:35am UTC](https://discourse.julialang.org/t/understanding-everywhere-and-environments/27438 "2019-08-12T01:35:20Z")\
**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:** [August 12, 2019, 1:35am UTC](https://discourse.julialang.org/t/understanding-everywhere-and-environments/27438/1 "2019-08-12T01:35:20Z")

</div>

I am working on a project that I’ve put into a module. The working directory of this module is in my `Base.load_path()` and running `using thvaccine` works as expected. I can be in the `v1.0` environment and still `using thvaccine` works.

However, when I try to execute on multiple workers (on local machine), it gives me an error.

```julia
julia> @everywhere using thvaccine
ERROR: On worker 2:
ArgumentError: Package thvaccine not found in current path:
- Run `import Pkg; Pkg.add("thvaccine")` to install the thvaccine package.

```

This is surprising to me since the path is available via `Base.load_path()` and that the main Julia process has no issues in locating the package. Anyways, the solution to this problem can be found [here](https://discourse.julialang.org/t/packages-and-workers/14072/10). Particularly, running

```julia
addprocs(4; exeflags="--project")
@everywhere using thvaccine

```

works perfectly. As far as I know the `--project` flags is essentially running `] activate .` But I am very confused here about how environment works. I thought environments really only matter for the `Project.toml` and `Manifest.toml` files. Infact, when I launch a fresh Julia and run `using thvaccine` in the v1.0 env (since the path is in `Base.load_path()`), everything works fine.

**I rarely ever even type `] activate .` except when I want to add a dependency to my project or run unit tests though `]`.**

So why is it that my workers need to be started with the project? How does “activating the environment” have anything to do with parallel workers. I feel like I have less ideal understanding of environments.

---

<div class="post-metadata">

**Author:** ![jmcastro2109](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmcastro2109/32/38427_2.png) [@jmcastro2109](https://discourse.julialang.org/u/jmcastro2109)\
**Post date:** [August 20, 2019, 4:27pm UTC](https://discourse.julialang.org/t/understanding-everywhere-and-environments/27438/2 "2019-08-20T16:27:27Z")

</div>

I have not been able to solve this very same issue. Even after, using the solution you propose. Do you have any idea on what might be happening?

I do not understand very well the intuition of the problem either.

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [August 20, 2019, 4:38pm UTC](https://discourse.julialang.org/t/understanding-everywhere-and-environments/27438/3 "2019-08-20T16:38:36Z")

</div>

> [@affans](#):
>
> This is surprising to me since the path is available via `Base.load_path()` and that the main Julia process has no issues in locating the package.

The worker processes do not execute `startup.jl`. This is likely why the `LOAD_PATH` does not point to you module. See the [docs](https://docs.julialang.org/en/v1/manual/parallel-computing/#Multi-Core-or-Distributed-Processing-1):

> Note that workers do not run a `~/.julia/config/startup.jl` startup script, nor do they synchronize their global state (such as global variables, new method definitions, and loaded modules) with any of the other running processes.

---

<div class="post-metadata">

**Author:** ![jmcastro2109](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmcastro2109/32/38427_2.png) [@jmcastro2109](https://discourse.julialang.org/u/jmcastro2109)\
**Post date:** [August 20, 2019, 5:45pm UTC](https://discourse.julialang.org/t/understanding-everywhere-and-environments/27438/4 "2019-08-20T17:45:08Z")

</div>

Then, what is the solution for this problem?

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [August 20, 2019, 8:32pm UTC](https://discourse.julialang.org/t/understanding-everywhere-and-environments/27438/5 "2019-08-20T20:32:52Z")

</div>

I don’t have too much experience with this, but I like to run code on remote machines in new, “clean” directories (no `Project.toml`). So I can control the environment and don’t have to worry about multiple processes interfering with each others’ environments.

Before starting anything remotely, I run a script that prepares the environment (basically running a couple of `Pkg.add` or `Pkg.develop`). When you then `activate` the prepared environment before running the actual code of interest, everything loads nicely.

---

<div class="post-metadata">

**Author:** ![Pbellive](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pbellive/32/3604_2.png) [@Pbellive](https://discourse.julialang.org/u/Pbellive)\
**Post date:** [August 20, 2019, 9:45pm UTC](https://discourse.julialang.org/t/understanding-everywhere-and-environments/27438/6 "2019-08-20T21:45:48Z")

</div>

This isn’t an elegant or general solution at all but in pinch you can always run

```julia
@everywhere push!(LOAD_PATH, "path-to-add")

```
