# Distributed is in stdlib, but preventing precompilation via being missing?

**URL:** <https://discourse.julialang.org/t/distributed-is-in-stdlib-but-preventing-precompilation-via-being-missing/127858>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [April 8, 2025, 4:02pm UTC](https://discourse.julialang.org/t/distributed-is-in-stdlib-but-preventing-precompilation-via-being-missing/127858 "2025-04-08T16:02:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JimCircadian](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jimcircadian/32/205596_2.png) [@JimCircadian](https://discourse.julialang.org/u/JimCircadian)\
**Post date:** [April 8, 2025, 4:02pm UTC](https://discourse.julialang.org/t/distributed-is-in-stdlib-but-preventing-precompilation-via-being-missing/127858/1 "2025-04-08T16:02:54Z")

</div>

This will be something really stupid I’m sure. I am having trouble loading Distributed **within** a package that is being developed, but having no problem when using it in the project from the REPL

```julia
$ julia --project

... Version 1.10.9 (2025-03-10)

julia> using Distributed

julia> addprocs(2)
2-element Vector{Int64}:
 2
 3

julia> x = @sync @distributed (+) for i in 1:1e9
              (i * 3) / (i ^ 3)
              end
4.9348021723201505

```

However, if I create a module:

```julia
(benchmarks) pkg> generate TestMod
  Generating project TestMod:
    TestMod/Project.toml
    TestMod/src/TestMod.jl

```

Add the following into `TestMod/src/TestMod.jl`

```julia
module TestMod

export mod_function

using Distributed

function mod_function()
	addprocs(2)
	x = @sync @distributed (+) for i in 1:1e9
    	(i * 3) / (i ^ 3)
	end
end

end # module TestMod

```

and then run via a julia REPL in my project:

```julia
$ julia --project

(benchmarks) pkg> dev TestMod/
   Resolving package versions...
    Updating `~/.../benchmarks/Project.toml`
  [981f2250] + TestMod v0.1.0 `TestMod`
    Updating `~/.../benchmarks/Manifest.toml`
  [981f2250] + TestMod v0.1.0 `TestMod`

julia> using TestMod
Info Given TestMod was explicitly requested, output will be shown live 
ERROR: LoadError: ArgumentError: Package TestMod does not have Distributed in its dependencies:
- You may have a partially installed environment. Try `Pkg.instantiate()`
  to ensure all packages in the environment are installed.
- Or, if you have TestMod checked out for development and have
  added Distributed as a dependency but haven't updated your primary
  environment's manifest file, try `Pkg.resolve()`.
- Otherwise you may need to report an issue with TestMod
Stacktrace:
 [1] macro expansion
   @ ./loading.jl:1846 [inlined]
 [2] macro expansion
   @ ./lock.jl:267 [inlined]
 [3] __require(into::Module, mod::Symbol)
   @ Base ./loading.jl:1823
 [4] #invoke_in_world#3
   @ ./essentials.jl:926 [inlined]
 [5] invoke_in_world
   @ ./essentials.jl:923 [inlined]
 [6] require(into::Module, mod::Symbol)
   @ Base ./loading.jl:1816
 [7] include
   @ ./Base.jl:495 [inlined]
 [8] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::Nothing)
   @ Base ./loading.jl:2292
 [9] top-level scope
   @ stdin:4
in expression starting at ~/.../benchmarks/TestMod/src/TestMod.jl:1
in expression starting at stdin:4
  ✗ TestMod
Precompiling TestMod finished.
  0 dependencies successfully precompiled in 2 seconds

ERROR: The following 1 direct dependency failed to precompile:

TestMod 

Failed to precompile TestMod [981f2250-5a9f-4a63-be36-82e31b8b2c23] to "~/.julia/compiled/v1.10/TestMod/jl_Uu3jVN".
ERROR: LoadError: ArgumentError: Package TestMod does not have Distributed in its dependencies:
- You may have a partially installed environment. Try `Pkg.instantiate()`
  to ensure all packages in the environment are installed.
- Or, if you have TestMod checked out for development and have
  added Distributed as a dependency but haven't updated your primary
  environment's manifest file, try `Pkg.resolve()`.
- Otherwise you may need to report an issue with TestMod
Stacktrace:
 [1] macro expansion
   @ ./loading.jl:1846 [inlined]
 [2] macro expansion
   @ ./lock.jl:267 [inlined]
 [3] __require(into::Module, mod::Symbol)
   @ Base ./loading.jl:1823
 [4] #invoke_in_world#3
   @ ./essentials.jl:926 [inlined]
 [5] invoke_in_world
   @ ./essentials.jl:923 [inlined]
 [6] require(into::Module, mod::Symbol)
   @ Base ./loading.jl:1816
 [7] include
   @ ./Base.jl:495 [inlined]
 [8] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::Nothing)
   @ Base ./loading.jl:2292
 [9] top-level scope
   @ stdin:4
in expression starting at ~/.../benchmarks/TestMod/src/TestMod.jl:1
in expression starting at stdin:

```

Am I being a bit dumb? Distributed is part of the standard library so why does it not load when contained within a module and instead suggest it should be installed? It could be I’m tired and not thinking straight, but regardless of it being a slightly weird thing to do, to wrap up distribution like this, surely it should be possible?

---

<div class="post-metadata">

**Author:** ![palday](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palday/32/12640_2.png) [@palday](https://discourse.julialang.org/u/palday)\
**Post date:** [April 8, 2025, 4:15pm UTC](https://discourse.julialang.org/t/distributed-is-in-stdlib-but-preventing-precompilation-via-being-missing/127858/2 "2025-04-08T16:15:45Z")

</div>

stdlibs still need to be added to a package’s environment/`Project.toml`. It’s not a problem running interactively in the REPL because of the way Julia stacks environments, but that global environment isn’t available inside of the module.

So you need to `]add Distributed` from within the `TestMod` environment.

---

<div class="post-metadata">

**Author:** ![JimCircadian](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jimcircadian/32/205596_2.png) [@JimCircadian](https://discourse.julialang.org/u/JimCircadian)\
**Post date:** [April 8, 2025, 4:19pm UTC](https://discourse.julialang.org/t/distributed-is-in-stdlib-but-preventing-precompilation-via-being-missing/127858/3 "2025-04-08T16:19:42Z")

</div>

Thanks @palday that makes a bit more sense, I’ll dig into that stacking of environments. Much appreciated.
