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

问题描述 投票:0回答:4

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

python pip anaconda pypi conda
4个回答
68
投票

您可以使用 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

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

如果您有一个项目依赖于 X 版本的“abc”,那么我们只需将其添加到该项目的 meta.yaml 中即可。示例:

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

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

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

14
投票

这有两个部分:如何创建通道以及如何使用通道。第二部分是最难做好的。

第一部分在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: {}

添加通道的语法没有记录,但阅读源代码正确的调用是:

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

(注意:

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

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

对于 MS Windows 设置中的任何人来说,与 Windows 共享一起使用的正确斜杠和反斜杠集是

file://\\SOMECORP\Corp\conda\channels\
。很有魅力。


1
投票

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

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

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


0
投票

Quetz 是 conda 包的开源服务器。你可以自己运行。

或者,如果您希望其他人为您托管频道,您可以使用 prefix.dev

© www.soinside.com 2019 - 2024. All rights reserved.