Opam install does not install dependencies automatically

Hi, I’m building a project with opam and dune.

According to the documentation of opam, command opam install . --deps-only --working-dir should install all the dependencies for me, but it didn’t do anything.

$ opam install . --deps-only --working-dir
$ dune build  
File "lib/dune", line 4, characters 12-20:
4 |  (libraries camomile))
                ^^^^^^^^
Error: Library "camomile" not found.
Hint: try:
  dune external-lib-deps --missing @@default
$ dune external-lib-deps --missing @@default
Error: The following libraries are missing in the default context:
- camomile
Hint: try:
  opam install camomile

Dune still wants me to install the dependencies manually.

Here is my dune-project file:

(package
 (name ...)
 ...
 (depends camomile))
          ^^^^^^^^

Here is my .opam file (generated by dune):

depends: [
  "dune" {>= "2.9"}
  "camomile"
  ^^^^^^^^^^
  "odoc" {with-doc}
]

Maybe the opam switch camomile has been installed in is not the one you are currently using.
Could you confirm this gives you the same result:

eval $(opam env)
dune build

Otherwise could you confirm camomile is installed:

opam list | grep camomile
1 Like

Maybe there is some confusion here? Opam is looking at your *.opam file, not your dune files. So you need to have the correct dependencies specified in the Opam file.

1 Like

Maybe try opam install . --deps-only --with-test --yes to install your dependencies.
I don’t use the --working-dir option but the docs don’t suggest it will do what you want.

-w, --working-dir
Whenever updating packages that are bound to a local,
version-controlled directory, update to the current working state
of their source instead of the last committed state, or the ref
they are pointing to. As source directory is copied as it is, if it
isn’t clean it may result on a opam build failure.This only affects
packages explicitly listed on the command-line.It can also be set
with $OPAMWORKINGDIR.

1 Like

Yes, it gives me the same result.

$ opam list | grep camomile
# nothing printed out

But I found another strange thing.

For the experiment, I uninstalled the uucp (another dependency I used).

$ opam uninstall uucp                         
The following actions will be performed:
  ⊘ remove uuseg 14.0.0 [uses uucp]
  ⊘ remove uucp  14.0.0
===== ⊘ 2 =====
Do you want to continue? [Y/n] y

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫 
⊘ removed   uuseg.14.0.0
⊘ removed   uucp.14.0.0
Done.

$ opam install . --deps-only --yes            
[NOTE] Ignoring uncommitted changes in /path/to/project (`--working-dir' not active).
[petite.0.1.0] synchronised (no changes)
The following actions will be performed:
  ∗ install uucp  14.0.0
  ∗ install uuseg 14.0.0
===== ∗ 2 =====

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫 
⬇ retrieved uuseg.14.0.0  (cached)
⬇ retrieved uucp.14.0.0  (cached)
∗ installed uucp.14.0.0
∗ installed uuseg.14.0.0
Done.

I don’t see the difference between uucp and camomile, which are both written in my dependencies.

I guess maybe there is a problem with the cache:

  • I removed the _build folder (It seems that this folder has nothing to do with opam, but I tried it anyway).
  • opam clean

But it doesn’t seem to help TAT.

Ah, I found the problem!

I’ve been thinking about why my CI always performs correctly, so I’m guessing it might have something to do with Git. I committed my changes on opam and run opam install again.

opam install . --deps-only --with-test
[petite.0.1.0] synchronised (git+file:///path/to/project#dev)
[petite] Installing new package description from upstream git+file:///path/to/project#dev
The following actions will be performed:
  ∗ install camomile 1.0.2
Do you want to continue? [Y/n] y

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫 
Processing  1/3: [camomile.1.0.2: dl]
⬇ retrieved camomile.1.0.2  (https://opam.ocaml.org/cache)
∗ installed camomile.1.0.2
Done.

--working-dir doesn’t seem to work the way I expected.

I still don’t understand some parts:

  • I’ve never used a package manager that is affected by a git commit before, what is the purpose of opam doing this? How could I get rid of this?
  • I’m using the dev Git branch for development. Is this the reason why opam is confused?

Anyway, at least my program is working now, thank you QAQ.

2 Likes

What is you opam version?

Likewise. opam version 2.1.4. --working-dir does nothing. The dependency is in the .opam file, but opam install . --deps-only --working-dir --with-test does not install the two dependencies I added. I added them to dune-project and ran dune build to generate the opam file, which it did correctly with the two dependencies I’d added to dune-project. But the opam install step says “Nothing to do”, opam list does not list them, and dune-build says they don’t exist.

I have the same problem with the latest opam and dune. I have the dependency (committed!) in my .opam file, but nonetheless when I run opam install . --deps-only it does not get installed. This is a really frustrating problem, and it has been an issue for years now. Any ideas on how to fix? It is only intermittently reproducible.

I have the same problem as Jon. I committed the modified opam file and the new decencies are installed when I run opam install. The --working-dir option has no effect. I tried opam clean but it didn’t help neither.

In addition, if I remove dependencies from the .opam file and uninstall the respective packages then these dependencies are still being installed when I run opam install . .

Where does opam look for the dependency information? It doesn’t seem to be the local .opam file.

I think I figured it out. It seems to be a ‘feature’ related to the pinning mechanism?

When I first run something like

opam install .

that will install a package pkg then pkg will get ‘pinned’. I can see pinned packages with

opam pin

When I run opam install . again then it will seemingly use the dependency information from that pinned package pkg instead of the info in pkg.opam. Runnning

opam pin remove pkg

will remove the pinned package and opam install . works (at least for me).

Hi Jan, I wanted to update you that there is a very closely related bug that is now tracked on the opam GitHub issue tracker here: opam install . --deps-only --working-dir incorrectly reports "Nothing to do" · Issue #5567 · ocaml/opam · GitHub.