我有几个相互依赖的Python项目。不同的项目有不同的发布版本,而且不同的项目可能依赖于特定项目的不同发布版本。我想在内部服务器上创建自己的conda仓库,以便将这些项目的发布版本作为conda包推送到该仓库,并使其他项目可以从中安装所需版本。是否可能?如果是,那么如何实现?
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 通道名称。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
-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)可以看到正确的调用方式:
添加频道的语法没有文档记录,但是通过阅读源代码(reading the source)可以看到正确的调用方式:
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\
。非常好用。
conda config --append channels file:///C:\tmp\my-conda-channel
请确保您按照Paul和Janus的答案中的说明操作。