opam install error "no solution found" - ocaml

I came across a bug when installing certain packages using opam.
> opam install foo
Sorry, no solution found: there seems to be a problem with your request.
No solution found, exiting

According to particular form of the error message I read you are using the opam v1.2 internal solver (which you can confirm via opam config report). This solver is no longer able to cope with the repository.
Either install an external solver, see here or switch to opam v2 (currently in rc) which bundles a decent solver.

Opam was using a version of the ocaml compiler that wasn't able to install this package. So unistall the current version and use opam switch to set opam to use the latest ocaml compiler.
> opam switch x.xx.x
Then make sure to update/upgrade opam.
> opam update
> opam upgrade

Related

opam switch list-available says no matches found

I tried following the installation process for opam. After that, I tried to use opam to install a package:
> opam install lwt
[ERROR] No switch is currently set. Please use 'opam switch' to set or install a switch
Then I try:
> opam switch list-available
# Listing available compilers from repositories: default
# No matches found
Last, I try this:
> opam switch create default
[ERROR] No compiler matching `default' found, use `opam switch list-available' to see what
is available, or use `--packages' to select packages explicitly.
I have OCaml 4.12.0 installed and opam version 2.1.0. What should I do to fix this?
If there are no switch available, you should try to update the opam repository first
opam update
It is likely that you are on a recently supported architecture (aka the Arm64/MacOS) and that there are no available switch for your architecture with your current package database.
If this doesn't work, you should check which repository you are using with opam -repo.

Using the most recent version of zarith with opam

I am using zarith for handling arbitrary sized integers.
The most recent version I could find on opam.ocaml.org was v1.9.1 (published in August 2019). On the project's github page I read Latest commit a9a309d on 23 Jan (2020).
I'd like to switch to the newer version, but how do I do that? I want to
keep opam happy, and
always use the most current version of zarith.
Please help!
Indeed, currently 1.9.1 is both the latest version of Zarith available as an opam package (https://opam.ocaml.org/packages/zarith/) and as a GitHub tag (https://github.com/ocaml/Zarith/tags).
However, given this upstream Git repository also contains an .opam specification file, you can just as well use opam to install the latest development version available in the master branch, or if need be, a precise Git commit just by relying on the so-called pinning feature of opam.
So, you can run alternatively:
opam pin add -n -y -k git zarith.dev --dev-repo
or
opam pin add -n -y -k git zarith.dev "https://github.com/ocaml/Zarith.git#master"
or
opam pin add -n -y -k git zarith.dev "https://github.com/ocaml/Zarith.git#a9a309d0596d93b6c0c902951e1cae13d661bebd"
Then:
opam install zarith
Further details on the opam-pin command
The .dev version suffix is unneeded syntactically, but is recommended actually, as the zarith.opam file does not specify any version. To be more precise:
If you have other dependencies that would complain of zarith.dev when being installed, you can replace the version suffix of dev with any compatible version string, "close" to the commit or branch you selected.
However if you omit this version, opam will typically pick the latest version string from the opam package repository (i.e., 1.9.1), which wouldn't necessarily match the code of the Git branch or commit you selected.
-n, -y, and -k are the short form of the options:
--no-action (don't install the package readily but wait the subsequent opam install command),
--yes (answer potential yes/no questions without prompting − a common opam pin question is Package foo does not exist, create as a NEW package? [Y/n] if ever you'd want to install a custom package not yet released in the opam-repository),
--kind=KIND (as there are several KINDS of pinning, the most typical being version, path, and git)
If you really need to use the unreleased, in-development version of zarith you can use the --dev-repo option of opam pin add:
opam pin add --dev-repo zarith
opam install zarith

Upgrading opam on Ubuntu 14.04

I'm trying to upgrade my opam to the latest version of Ubuntu 14.04
chris#chris-870Z5E-880Z5E-680Z5E:~$ sudo opam update
default Downloading https://opam.ocaml.org/1.1/urls.txt
Updating ~/.opam/repo/compiler-index ...
Updating ~/.opam/compilers/ ...
Updating ~/.opam/repo/package-index ...
Updating ~/.opam/packages/ ...
The following package has been DELETED:
- camlp4.4.02.0+2
[WARNING] install and dev-repo are unknown fields in /home/chris/.opam/repo/default/packages/liquidsoap/liquidsoap.1.1.1/opam: is your OPAM up-to-date ?
[WARNING] install is an unknown field in /home/chris/.opam/repo/default/packages/ocurl/ocurl.0.7.2/opam: is your OPAM up-to-date ?
Updating the cache of metadata (~/.opam/state.cache) ...
23 to install | 17 to reinstall | 16 to upgrade | 1 to downgrade | 0 to remove
You can now run 'opam upgrade' to upgrade your system.
chris#chris-870Z5E-880Z5E-680Z5E:~$ sudo opam upgrade
[WARNING] External solver failed with inconsistent return value. Request saved to "/home/chris/.opam/log/solver-error-6572-1.cudf"
Falling back to the internal heuristic.
The dependency ocamlbuild of package variantslib.109.15.03 is not available for your compiler or your OS.
'opam upgrade' failed.
As the error message says, it appears that variantslib.109.15.03 is not available on my OS/compiler version. Is there any way I can get around this? Here is my compiler version:
chris#chris-870Z5E-880Z5E-680Z5E:~$ ocaml -version
The OCaml toplevel, version 4.02.0
First of all, don't use sudo as opam is installed in your user folder, so you may actually break it by locking it from yourself. (I think you already did it). In general, don't use sudo if you're not absolutely sure what you're doing.
The solver is unable to find a package variantslib that will fit into constraints of your system. If you're installing or using some package, that you believe should work for the Ubuntu 14.04 LTS, then I would suggest you just to start from a clean state and install it, instead of performing the update. Since you already messed with sudo, I would actually suggest you to remove the ~/.opam folder, and start with
opam init
And install whatever you need from scratch.
If I remember well, I had some issues with opam 1.1 in the past... And the opam FAQ states that you should move to opam 1.2 (because of : ubuntu bugs).... I personally use opam 1.2.2 (on ubuntu 16.04 & 12.04...)

Opam switch install could not install the older version of ocaml (3.08.3)

I'm doing some works with ocaml and opam.
I need ocaml of version 3.08.3, so I tried install this version via opam.
opam switch install 3.08.3
The above command would install it successfully, I hoped. But it couldn't.
opam-switch could not install 3.* versions of ocaml with the following error message.
[ERROR] Could not resolve set of base packages
I searched this message everywhere, but I couldn't get any of hints. Does anyeone have a clue to solve this problem? Thanks.
compilers/3.08.3/3.08.3/3.08.3.comp, the file to describe the base packages for that compiler version tells:
packages: [
"base-unix"
"base-bigarray"
"base-threads"
"base-ocamlbuild"
]
So it requires base-unix, base-bigarray, base-threads and base-ocamlbuild. However, the package description of base-ocamlbuild, packages/base-ocamlbuild/base-ocamlbuild.base/opam says:
ocaml-version: [>= "3.10" & < "4.03"]
It says that ocamlbuild is not available before 3.10. Indeed, ocamlbuild was introduced since 3.10. It is likely that the compiler description file 3.08.3.comp has a bug. It is great if you would raise a bug ticket at https://github.com/ocaml/opam-repository/issues for the fix.
For a workaround, I recommend to install OCaml 3.08 by hand, not using OPAM command: I see almost no benefit to use OPAM with 3.08 where ocamlbuild is not available, since most of the OPAM packages assume the existence of ocamlbuild.
You could also create your own copy of OPAM repo with a fixed 3.08.3.comp file without "base-ocamlbuild". See the document of opam repo for more details.

Opam not getting latest packages

I just installed opam using the quick install
http://opam.ocaml.org/doc/Quick_Install.html
I now have
$opam --version
1.1.0
which is current. I ran "opam update" and "opam upgrade" to get the latest packages. However, when I install packages, it is still giving me the old versions (such as core 109.42 instead of core 109.55):
$ opam search core
Available packages for 4.01.0:
async_core 109.42.00 Monadic concurrency library
What do I need to do to get opam to give me the latest libraries?
If you previously built from source, make sure you uninstall that first. For whatever reason, even though the opam version correctly reports "1.1.0", it was still using the old repo address. After you uninstall old opam entirely, then follow the installation instructions at the link above.
You will know you succeeded when you do "opam update" and prints:
default Downloading http://opam.ocamlpro.com/urls.txt
[NOTE] The repository 'default' will be *permanently* redirected to https://opam.ocaml.org (opam-version >= "1.1.0")