ERROR: Unsatisfiable requirements detected for package HDF5 [f67ccb44]

Environments allow you to specify a particular set of Julia packages (with specific versions) for a given project. When you use the default environment and install a large number of packages, you are more likely to have a conflict between dependencies. For example, Package A might require the version of Package C to be less than or equal to 2.0, while Package B requires the version of Package C to be greater than or equal to 3.0. By only including the packages a particular project requires, you’ll probably find you have fewer dependency conflicts.

Let’s say I want to make a new environment for my project in directory MyProject which uses DataFrames and CSV.

From the shell:

mkdir MyProject
cd MyProject
julia

From the Julia REPL:

using Pkg
Pkg.activate(".")
Pkg.add("DataFrames")
Pkg.add("CSV")

The single argument for Pkg.activate is the path to the project directory, and if you started Julia from the project directory, then it’s simply the current working directory: ".". You should now see that there are two files in MyProject, Project.toml and Manifest.toml. The former is a list of the declared dependencies of the project and looks like this:

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"

The Manifest.toml file contains all of the direct and indirect dependencies, along with their specific versions. Normally, you don’t have to edit these files directly, that’s what the Pkg module is used for.

In any Julia script that you write that you want to use these dependencies, you simply activate the project environment at the beginning, for example:

using Pkg
Pkg.activate(".")
using DataFrames
using CSV
df = CSV.read("some_table.csv", DataFrame)

While it is a little more overhead to get started with a project environment, it makes things so much easier to reproduce the same results you got when you last left the project (potentially months or years later).

You can find more information about environments in the documentation here:
https://pkgdocs.julialang.org/v1/environments/

1 Like