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?