Instantiate vs Resolve: Which Approach Safely Recovers a Corrupted Julia Environment?
0 reputation · 22 Jul 2020, 13:33 UTC
0 reputation · 22 Jul 2020, 13:33 UTC
After a failed Julia package upgrade, the user wants to restore a functional environment that previously compiled successfully.
During the upgrade, the Manifest.toml was modified to include an impossible or incompatible version entry for a package, causing subsequent using statements to error. The user has a backup of the original Manifest but does not know whether the recorded versions are still available on the registry.
Two documented Pkg commands can be used: Pkg.instantiate() reinstalls the exact versions listed in the Manifest, while Pkg.resolve() recomputes a compatible set of versions based on the Project.toml constraints, potentially selecting newer releases.
Pkg.instantiate() always restore the pre‑upgrade state, or can it propagate existing incompatibilities?Pkg.resolve() guarantee a working configuration, and how does it handle the impossible version entry?35275 reputation · 22 Jul 2020, 20:17 UTC
To recover a functional environment from a known backup, you should restore the backup Manifest.toml first, then run Pkg.instantiate(). Pkg.instantiate() is the only command that guarantees an attempt to restore the exact state recorded in the Manifest. Pkg.resolve() should be avoided during initial recovery because it ignores the existing Manifest's specific version pins and attempts to calculate a new dependency graph, which may lead to different package versions than those used in your previously working state.
Understanding the distinction between these two commands is critical when dealing with a corrupted Manifest.toml:
Manifest.toml as the source of truth. It downloads and installs the exact versions and artifacts specified in that file.Project.toml. It then writes a new Manifest.Follow these steps to safely restore your environment (assuming Julia 1.6+):
Manifest.toml with your backup copy.import Pkg; Pkg.instantiate()
Pkg.status()
This approach assumes that the Project.toml remains unchanged and that the registry versions referenced in the backup Manifest are still hosted. If Pkg.instantiate() fails with a "version not found" error, it indicates the registry has purged those specific versions, at which point Pkg.resolve() becomes the necessary fallback to find the next best compatible versions.
Missing Diagnostic: Are you using a custom local registry or the standard General registry? If using a private registry, Pkg.instantiate() will fail unless the registry URL is correctly configured in your local environment.
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 22 Jul 2020, 18:07 UTC
When a Manifest.toml contains an impossible pin, Pkg.instantiate() will try to fetch that exact version and abort if it cannot be found. The safe pattern is to delete the corrupt file and let Julia rebuild it:
rm("Manifest.toml") (or clear ~/.julia/registries if the registry is suspect)Pkg.instantiate() – it falls back to Project.toml and writes a fresh manifest, pulling the newest compatible releases when the original pin is missing.Pkg.resolve() to tighten constraints or add new dependencies.In Julia 1.7+, Pkg.instantiate() automatically resolves missing pins; earlier 1.x releases may still need a preceding Pkg.resolve() before instantiate.