如何托管我自己的私有 conda 存储库?

How can I host my own private conda repository?

我有几个 python 项目相互依赖。每个项目都有不同的发布版本,不同的项目可能依赖于特定项目的不同发布版本。我想在内部服务器上创建自己的 conda 存储库,在那里我可以将这些项目的版本作为 conda 包推送,其他项目可以从那里安装所需的版本。这可能吗?如果有怎么办?

您可以使用 conda custom channel 作为您的私人仓库。基本步骤是使用 "conda build" 创建一个 conda 包,然后将该包复制到您的自定义频道(一个目录),现在 运行 在该目录上创建 conda 索引。然后,您可以使用 "conda install -c ".

从该频道安装软件包

一个例子,更详细地说,我们假设linux-64:

  • 创建频道:
    mkdir -p /tmp/my-conda-channel/linux-64
  • 现在假设您有一些名为 "abc" 的项目,带有 meta.yaml 和 build.sh 以及一些版本 X。现在您构建它:

    conda build abc

  • 这将在您的 conda-bld 目录中构建一个 tar.bz2 文件。例如:~/miniconda3/conda-bld/linux-64/abc-X-py35_0.tar.bz2。将该文件复制到您的频道:

    cp ~/miniconda3/conda-bld/linux-64/abc-X-py35_0.tar.bz2 /tmp/my-conda-channel/linux-64/

  • 现在索引它:

    conda index /tmp/my-conda-channel/linux-64/

您现在已经将该包上传到您的自定义频道。您可以通过执行以下操作将其安装在任何 conda 环境中:

conda install -c file://tmp/my-conda-channel/ abc=X

回想一下,X 是版本,因此,一旦您在频道中放置了更多版本,就可以安装特定版本。

如果您的项目依赖于 "abc" 的 X 版本,那么我们只需将其添加到该项目 meta.yaml。示例:

package:
  name: some-other-project
  version: 0.1
requirements:
  build:
   - abc X
...

创建此频道后,最好将其添加到 .condarc 文件中,以便系统自动搜索它。例如:

channels:
- file://tmp/my-conda-channel/   
- defaults

这有两个部分:如何创建频道和如何使用它。第二部分是最难做好的。

第一部分在conda documentation中有详细介绍。 您可以直接从文件或通过静态网络服务器为频道提供服务。

要使用频道,一种方法是 -c file://tmp/my-conda-channel/,但最近的 conda 版本通过 自定义频道 提供了更好的解决方案,其中(最近?)添加到康达

文档可通过 conda config --describe 获得,其中包括以下部分:

# custom_channels (map: str)
#   A map of key-value pairs where the key is a channel name and the value
#   is a channel location. Channels defined here override the default
#   'channel_alias' value. The channel name (key) is not included in the
#   channel location (value).  For example, to override the location of
#   the 'conda-forge' channel where the url to repodata is
#   https://anaconda-repo.dev/packages/conda-forge/linux-64/repodata.json,
#   add an entry 'conda-forge: https://anaconda-repo.dev/packages'.
#
# custom_channels: {}

没有记录添加频道的语法,但reading the source正确的调用是:

conda config --set custom_channels.my-conda-channel file://tmp/

(注意:my-conda-channel/ 不是路径的一部分)。 将此添加到您的配置后,您现在可以像 conda-forge 或其他 'built-in' 频道一样使用自己的频道:

conda install -c my-conda-channel my-cool-package

对于 MS Windows 设置中的任何人,与 windows 共享一起使用的正确斜杠和反斜杠集是 file://\SOMECORP\Corp\conda\channels\。很有魅力。

如果您想在 Windows 上添加频道,请尝试:

conda config --append channels file:///C:\tmp\my-conda-channel

确保您遵循了 Paul 和 Janus 的回答中的说明。