emacs ocaml REPL:"Searching for program: no such file or directory, ocaml"

emacs ocaml REPL: "Searching for program: no such file or directory, ocaml"

我正在尝试在 VirtualBox 上的 Ubuntu 16.04.3 中设置 OCaml。我对他们都是新手;请原谅我的无知。我使用

安装了 opam
wget https://raw.github.com/ocaml/opam/master/shell/opam_installer.sh -O - | sh -s /usr/local/bin

并添加

. /home/<username>/.opam/opam-init/init.sh > /dev/null 2> /dev/null || true
根据 opam 安装后的说明

添加到我的 ~/.profile 文件。我使用 opam install tuareg 安装 tuareg,使用 sudo apt-get install emacs 安装 GNU emacs 24.5.1

当我尝试通过在 emacs 中键入 M-x run-ocamlreturn 来使用 ocaml REPL 时,我得到了 OCaml REPL to run: ocaml;当我再次点击 enter 时,我得到了

Searching for program: no such file or directory, ocaml

然后我尝试 M-x shell 看看我是否可以从 shell 运行 ocaml,我注意到我每次都需要使用 opam switch我想从terminal/shell运行ocaml;如果我直接输入 ocaml,我会得到

The program 'ocaml' is currently not installed. You can install it by typing: sudo apt-get install ocaml-interp

我不确定这是否与我遇到的问题有关。

作为第二次尝试,我回到 emacs 并输入 M-x run-ocaml,点击 return,然后在 OCaml REPL to run: 处再次点击 return(这次没有 ocaml).这打开了一个新缓冲区:

但是当我尝试在新缓冲区中输入内容时,说 1+1;;,然后点击 shift-return,我得到 Output file descriptor of OCaml is closed,如上所示。

我一直在阅读不同的文档和线程以获取说明,但其中 none 完全描述了我的情况。任何帮助将不胜感激!

也许你应该尝试 M-x run-ocamlreturn,然后键入 /usr/bin/opam config exec -- ocaml(或任何你的 opam 安装路径)而不是 ocaml

所以我按照realworldocaml解决了这个问题。我意识到我的 post 中有几个问题,所以我使用这个答案来 按照 link 中的建议与每个人分享解决方案。

@ghilesZ的回答完美解决了我问题标题中的问题(谢谢!)。我应该在 M-x 命令(如上述答案所建议的)或 ~/.emacs 配置文件(如 link 建议的)中添加 ocaml 的路径。完成以下步骤后,在终端中输入which ocaml即可获取路径。

需要打字

eval `opam config env`

to 运行 ocaml 从终端可以通过将行添加到 ~/.bashrc 文件来解决。这是因为在当前 shell 中键入命令只会为当前 shell 设置内容。为了将来 shell 能够自动设置,需要在登录脚本中添加。