How to import JSON when using parallel mode?

Hi,

I’d like to parallelize my program so I start my program with

julia --project -p 2 -L a.jl main.jl

where the computation is in a.jl and main.jl is a driver script. Inside a.jl I import JSON, and if I don’t add the -p 2 argument the program will run fine, but with this option, I now have the error:

ERROR: On worker 2:
LoadError: ArgumentError: Package JSON not found in current path:
- Run `import Pkg; Pkg.add("JSON")` to install the JSON package.

It seems like I’m missing something, like instruct the workers to also include the libraries. What should I do in this case?

Thanks!

You need to tell the worker processes to also use the local project like this:

import Pkg; Pkg.activate(".")
using JSON

In the future, it would be great if worker processes automatically adopted the project of the main process.

2 Likes