Problem with distributed, @everywhere using gives error on workers

julia> using MuladdMacro

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

I’ve seen tonnes of posts on this, and none of them offered a fix to my problem. I’ve never had JuliaPro on this laptop, which is a common cause of this error apparently.

julia> Base.load_path()
3-element Array{String,1}:
 "\\home\\peter\\.julia\\environments\\v1.4\\Project.toml"
 "C:\\Users\\pjent\\.julia\\environments\\v1.4\\Project.toml"
 "C:\\Julia-1.4.2\\share\\julia\\stdlib\\v1.4"

julia> remotecall_fetch(Base.load_path, 2)
2-element Array{String,1}:
 "C:\\Users\\pjent\\.julia\\environments\\v1.4\\Project.toml"
 "C:\\Julia-1.4.2\\share\\julia\\stdlib\\v1.4"

The top entry in load_path is from a cluster I use the VSCode Remote SSH extensions to use. Maybe that’s the problem?

I tried completely removing and adding Julia, but this problem remains. I guess I left a bit behind?

I am not sure if I understand. Are your workers in the same machine? If one of your workers is in a remote machine and you do not have your package installed there, it cannot load the package. To be sure they are installed, do what the message says, and at least one time call:

@everywhere import Pkg
@everywhere Pkg.add("MuladdMacro")

Sorry, yes they are on the same machine, which is why it’s so confusing.

When you start your julia session are you in a particular environment? that is, are you doing julia --project=/some/project , or alternatively, are you changing the environment programatically once Julia is launched i.e ] activate env

If you are using an environment/project (i.e., Project.toml/Manifest.toml files) it may be necessary to call Pkg.activate("path/to/folder/with/toml/files/") in the workers (with @everywhere). Also, note that @everywhere only executes the code in the workers currently running. So if you do some setup with @everywhere before calling addprocs (or some other method to create workers) those newly created workers will not have executed the setup you did with @everywhere before.

Adding to the previous answer (and based on my reply), you could also do

addprocs(n, exeflags="--project=/path/project")

It seems like I wasn’t starting up in the default environment. Thanks! VSCode automatically starts up in the folder environment if the folder is a package.

1 Like

I personally don’t agree that the idea of this issue should be implemented (unless there is an explicit command by the user to do so), but it explains the problem that you’re hitting.

2 Likes