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

Nef*_*ous 28 python pip pypi anaconda conda

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

Pau*_*aul 38

您可以使用conda自定义渠道作为私人仓库.基本步骤是使用"conda build"创建一个conda包,然后将该包复制到您的自定义通道(目录)中,现在在该目录上运行conda index.然后,您可以使用"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
Run Code Online (Sandbox Code Playgroud)

在哪里,回想一下,X是版本,所以,一旦你在频道中放置了更多版本,你就可以安装特定的版本.

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

package:
  name: some-other-project
  version: 0.1
requirements:
  build:
   - abc X
...
Run Code Online (Sandbox Code Playgroud)

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

channels:
- file://tmp/my-conda-channel/   
- defaults
Run Code Online (Sandbox Code Playgroud)

  • 这是有关在Docker容器中运行nginx来服务conda频道的博客。https://www.cityscience.com/blog/private-conda-channel.html (3认同)
  • @RolandWeber 的链接已腐烂:这是更新的链接 https://www.cityscience.com/news/2017-02-09-private-conda-channel/ (3认同)
  • 有任何方法可以通过http访问您的频道吗? (2认同)
  • @Machiel 这个问题提到了一个内部服务器,但没有提到 http。答案可以与内部文件服务器一起使用。 (2认同)

Jan*_*nus 6

这包括两部分:如何创建通道以及如何使用它。第二部分是最难做到的。

第一部分在conda文档中进行了详细描述。您可以直接通过文件或通过静态网络服务器投放渠道。

要使用该渠道,一种方法是-c file://tmp/my-conda-channel/,但是最新的conda版本可以通过自定义渠道(在最近(?)添加到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: {}
Run Code Online (Sandbox Code Playgroud)

没有记录添加通道的语法,但是在读取源代码时可以看到正确的调用是:

conda  --set custom_channels.my-conda-channel file://tmp/
Run Code Online (Sandbox Code Playgroud)

(注意:my-conda-channel/这不是路径的一部分)。将此添加到您的配置后,您现在可以使用自己的频道,conda-forge或使用其他“内置”频道的方式:

conda install -c my-conda-channel my-cool-package
Run Code Online (Sandbox Code Playgroud)

对于使用MS Windows设置的用户,将其与Windows共享一起使用的正确的斜杠和反斜杠设置为file://\\SOMECORP\Corp\conda\channels\。很有魅力。