What is the difference between Pkg.resolve and Pkg.instantiate?

The documentation for resolve and instantiate don’t explain this thoroughly.
When is Pkg.resolve useful? I notice that resolve fails if there is no registry installed. Whereas instantiate will automatically install a missing registry.

The docs led me to believe, although they don’t say it explicitly, that resolve will only, possibly, compute and write a new Manifest.toml. But, in fact, if the depot is empty, it will download the packages, just like instantiate.

1 Like

If you don’t have a Manifest.toml, then they’re equivalent. If you do, then:

  • instantiate will download and precompile any packages that are listed in the Manifest.toml
  • resolve will first check that the Manifest.toml is consistent with the Project.tomls of the current project and all its dependencies, updating it if necessary, then instantiate.
    • this is particularly useful during development: e.g. if you’re using a dev-ed dependency of a package and add a new dependency to it, then you need to go resolve your top project to make sure these changes are reflected in its Manifest
  • update will use the newest possible dependencies (subject to compatibility constraints)
4 Likes

That seems like a bug to me.

Yes. If this is not correct:

doresolve.jl

import Pkg

mkdir("./newproj")
mkdir("./newdepot")
Pkg.activate("./newproj")
Pkg.add("Example")
rm("./newproj/Manifest.toml")
save_depot = copy(DEPOT_PATH)
empty!(DEPOT_PATH)
push!(DEPOT_PATH, abspath("./newdepot"))
Pkg.resolve()
julia> include("doresolve.jl")
  Activating new project at `~/resolvebug/newproj`
   Resolving package versions...
    Updating `~/resolvebug/newproj/Project.toml`
  [7876af07] + Example v0.5.3
    Updating `~/resolvebug/newproj/Manifest.toml`
  [7876af07] + Example v0.5.3
ERROR: LoadError: expected package `Example [7876af07]` to be registered

But starting again from scratch and using instantiate rather than resolve does work. In particular part of the output is Installing known registries into~/resolvebug/newdepot``