`$ julia -p n` can't use Project.toml?

Basic script:

me@pc:/tmp/testenv$ less /tmp/testproj/test.jl 

using Optim,DataFrames

DataFrame(rand(3,3))

Project has all deps:

me@pc:/tmp/testenv$ less /tmp/testproj/Project.toml 

./Project.toml

me@pc:/tmp/testenv$ less /tmp/testproj/Project.toml 
[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Optim = "429524aa-4258-5aef-a3af-852621145aeb"
Project.toml (END)

According to the docs, the correct way to specify a project when calling in bash is:

me@pc:/tmp/testenv$ julia -p 5 --project=/tmp/testproj ./test.jl

This is super annoying:

No info about the status of the project that I requested to be activated, just apparently silently failing:

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

Try ignoring the docs and use interactive way:

me@pc:/tmp/testenv$ less /tmp/testproj/test.jl 

using Pkg
Pkg.activate("/tmp/testproj")
using Optim,DataFrames

DataFrame(rand(3,3))

Exact same problem:

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

This is unfortunately a long standing issue with Distributed workflows: Workers should inherit Pkg environment · Issue #28781 · JuliaLang/julia · GitHub

One of the easiest workarounds is to use the JULIA_PROJECT environment variable — from bash it’s just:

$ JULIA_PROJECT=/tmp/testproj julia -p 5 ./test.jl
3 Likes

Yeah this is clearly going to get fixed, but the most urgent issue is the documentation.

I hate to lay this at someone else’s feet but most people (eg myself) who are getting tripped up by this do not have the expertise to do a PR for the manual, at least without it looking totally ad hoc.

Right now the documentation on the julia environment is fragmented because:

have semantic inconsistencies in their functionality as you pointed out and this can only be handled by a more unified treatment which currently does not exist to my knowledge.