[opam-devel] opam installs package but ocamlfind fails

Thomas Gazagnaire thomas at ocamlpro.com
Tue Apr 2 08:52:44 BST 2013


> So my environment variable are out of sync with the current switch.

This can sometimes happen when $OPAMSWITCH is (usually wrongly) set. Try `unset OPAMSWITCH` before running your eval command, you add `--switch=<your-switch>` to the config command. I am aware this is quite annoying, I'm still trying to find a good solution to this which still enables some useful use-cases. But this particular issue should be fixed in master.

The issue is:
* by default OPAM look at ~/.opam/config to get the value of the current switch
* if OPAMSWITCH is set, OPAM will consider the value of that variable to be the current switch
* this can be overwritten by --switch=<..>

When exporting the environment variables (eg. using `opam config env`) OPAM 1.0 always export OPAMSWITCH with the current compiler switch (this was needed to make `opam config exec` works as expected). In master, OPAMSWITCH is not read when we do `opam config env`, which then export the right *global* variables.

> I used to do "eval `opam config eval`" in my login scripts, but I thought the below meant I should now just source ~/.opam/opam-init/init.sh. This can't be right though because, after looking into opam-init.sh, I see that setting environment variables to the 4.00.1 switch (the initial switch I installed) is hardcoded.

In an init script, you don't need to eval `opam config env`, you can just source ~/.opam/opam-config/init.sh. This will simply export the right global environment variables (corresponding to the value of the switch in ~/.opam/config) and will optionally enable auto-completion. It's still correct to run eval though. And after a switch you still need eval, because you want to dynamically rewrite the contents of some of your variables, for instance:
PATH=~/.opam/foo/bin:XXX
into
PATH=~/.opam/bar/bin:XXX

> Could we get some clarification on what the init.sh script is supposed to do exactly. Is calling "eval `opam config eval`" still required in our login scripts? If so, note that `opam init --auto-setup` doesn't do that.

You can look at the init script itself:

$ cat ~/.opam/opam-init/init.sh
# Load the environment variables
. /Users/tgazagna/.opam/opam-init/variables.sh

# Load the auto-complete scripts
. /Users/tgazagna/.opam/opam-init/complete.sh

# Load the opam-switch-eval script
. /Users/tgazagna/.opam/opam-init/switch_eval.sh

--
Thomas

> 
> 
> On Thu, Mar 14, 2013 at 4:28 PM, Thomas Gazagnaire <thomas at ocamlpro.com> wrote:
> ... 
> The most visible new feature, which should be useful for beginners with OCaml and OPAM,  is an auto-configuration tool. This tool easily enables all the features of OPAM (auto-completion, fix the loading of scripts for the toplevel, opam-switch-eval alias, etc). This tool runs interactively on each `opam init` invocation. If you don't like OPAM to change your configuration files, use `opam init --no-setup`. If you trust the tool blindly,  use `opam init --auto-setup`. You can later review the setup by doing `opam config setup --list` and call the tool again using `opam config setup` (and you can of course manually edit your ~/.profile (or ~/.zshrc for zsh users), ~/.ocamlinit and ~/.opam/opam-init/*). ...
>  
> 
> 
> On Sun, Mar 31, 2013 at 10:01 AM, Nicolas Braud-Santoni <nicolas at braud-santoni.eu> wrote:
> Did you check, using `which ocamlfind`, that you are indeed using the
> ocamlfind installation from OPAM ?
> 
> On 30/03/2013 22:10, Ashish Agarwal wrote:
> > `opam install pxp` succeeds and `opam info pxp` shows that it is
> > installed. However,
> >
> > $ ocamlfind query pxp
> > ocamlfind: Package `pxp' not found
> >
> > This is only happening on one of my computers. On another, ocamlfind
> > does recognize pxp. I'm installing the same versions of all packages.
> > How can I investigate further?
> 
> _______________________________________________
> opam-devel mailing list
> opam-devel at lists.ocaml.org
> http://lists.ocaml.org/listinfo/opam-devel



More information about the opam-devel mailing list