How to activate the current project with Distributed

I am trying to activate the current project with Distributed, which fails:

using Distributed

@everywhere begin
  using Pkg; Pkg.activate(@__DIR__)
  Pkg.instantiate(); Pkg.precompile()


julia> include("src/dist.jl")
  Activating project at `~/repos/WindTurbines/src`
      From worker 7:      Activating project at `~/repos/WindTurbines/src`

It tries to find Project.toml in the folder src, but it is in the base folder.

How can I fix that?

If your source file is src/dist.jl, then within it @__DIR__ == "/path/to/project/src". So you have to go up one directory to retrieve the top-level project directory:

@everywhere begin
    import Pkg
    Pkg.activate(joinpath(@__DIR__, ".."))

If your julia depot is on a shared filesystem, I would also recommend to take the appropriate steps for the project to be compiled on one node beforehand, so that when starting the distributed computations everything is already done. Last time I checked, problems could arise if several processes attempted to precompile the same set of packages at the same time.

1 Like