简体   繁体   English

在 OPAM 中安装软件包列表

[英]Installing a list of packages in OPAM

OPAM is a great Package Manager for OCaml. OPAM是 OCaml 的出色 Package 管理器。

Is there a way to install a given list of packages like pip does in Python (with the command pip -r requirements.txt )?有没有办法在 Python 中安装给定的软件包列表,如pip (使用命令pip -r requirements.txt )?

We have a small Git repo shared with several people and it would be nice to just install all project dependencies in one go.我们有一个与几个人共享的小型 Git 存储库,最好将所有项目依赖项安装在一个 go 中。

And yes, we might have a little shell script or list the packages in a.txt file and pipe it to opam install ... but there might be a better solution.是的,我们可能有一点 shell 脚本或列出 a.txt 文件中的包和 pipe 以进行opam install ......但可能有更好的解决方案。

Thanks谢谢

Assuming you have your dependencies specified in NAME.opam (or just opam ) file in your project, you can run假设您在项目的NAME.opam (或只是opam )文件中指定了依赖项,您可以运行

opam install . --deps-only

This will install all dependencies for your package (or packages if you have several opam files in your project).这将为您的 package 安装所有依赖项(如果您的项目中有多个 opam 文件,则安装软件包)。

By default opam ignores uncommitted changes, so if you want to run this command with modified opam files you'll need to add --working-dir .默认情况下 opam 会忽略未提交的更改,因此如果您想使用修改后的 opam 文件运行此命令,您需要添加--working-dir

Optionally you could lock down versions of dependencies used by running opam lock , this will create .opam.locked files.或者,您可以锁定运行opam lock使用的依赖项版本,这将创建.opam.locked文件。 opam-lock is a separate plugin in 2.0.5 (and likely until 2.1), so opam will prompt to install it. opam-lock是 2.0.5 中的一个单独插件(可能直到 2.1),所以 opam 会提示安装它。

With lock files present, you should also add --locked to opam install to ask it to use lock file and install exactly the same versions.如果存在锁定文件,您还应该将--locked添加到opam install以要求它使用锁定文件并安装完全相同的版本。

I would also recommend adding -j X where X is the number of cores you have available, that will speed things up.我还建议添加-j X ,其中X是您可用的内核数,这将加快速度。

I typically have the following in my Makefiles:我的 Makefile 中通常有以下内容:

deps:
        opam install . --deps-only --locked --working-dir

The syntax of .opam files is described here .opam文件的语法在此处描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM