简体   繁体   English

除非必要,否则如何避免使用 conda-forge 包?

[英]How to avoid using conda-forge packages unless necessary?

I'm running into a minor but annoying issue with conda when installing individual packages from conda-forge.从 conda-forge 安装单个软件包时,我遇到了一个小而烦人的 conda 问题。 Typically I'd run something like this:通常我会运行这样的东西:

conda install -c conda-forge somepackage

This has the effect of frequently updating other packages using conda-forge: almost always ca-certificates, certifi and openssl;这具有使用 conda-forge 频繁更新其他软件包的效果:几乎总是 ca-certificates、certifi 和 openssl; and sometimes major packages like python, numpy etc (all from conda-forge).有时像 python、numpy 等主要软件包(全部来自 conda-forge)。 I suspect these updates are not strictly necessary;我怀疑这些更新并不是绝对必要的; those packages get pulled in using some logic along the lines of "in order to install the latest version of somepackage I need python>=3.8 but the current python is 3.7; I can use conda-forge, so I'll get the latest python from conda-forge which is newer than the one in default".这些包使用一些逻辑按照“为了安装 somepackage 的最新版本,我需要 python>=3.8,但当前 python 是 3.7;我可以使用 conda-forge,所以我会得到最新的 python来自 conda-forge,它比默认的更新”。

What I would like to accomplish is: install any version of somepackage (not necessarily latest) while installing as little as possible from conda-forge.我想要完成的是:安装 somepackage 的任何版本(不一定是最新的),同时尽可能少地从 conda-forge 安装。 In particular, if there is a choice between keeping an already installed package and upgrading, I always want to keep;特别是,如果在保留已安装的 package 和升级之间进行选择,我总是想保留; and if there is a choice between default channel and conda-forge, I always want default (even if those choices result in ending up with older versions of the new packages I'm trying to install, and/or their new dependencies - but not if they result in the install being impossible).如果在默认通道和 conda-forge 之间有选择,我总是想要默认(即使这些选择导致我尝试安装的新软件包的旧版本和/或它们的新依赖项 - 但不是如果它们导致无法安装)。

How do I accomplish this?我该如何做到这一点?

how do I tell conda "don't upgrade dependencies"我如何告诉 conda“不要升级依赖项”

One can use conda install --freeze-installed PACKAGE... ( documentation ) to prevent conda from updating packages that are already installed.可以使用conda install --freeze-installed PACKAGE...文档)来防止 conda 更新已安装的软件包。 This does not, however, seem to prevent updating of packages under the aggressive_update_packages key of conda's config.然而,这似乎并不能阻止在aggressive_update_packages配置的 Aggressive_update_packages 键下更新包。 The default packages there are ca-certificates , certifi , and openssl (see the default configuration ).默认包有ca-certificatescertifiopenssl (见默认配置)。 One can check their own configuration with可以检查自己的配置

conda config --show aggressive_update_packages

install any version of somepackage (not necessarily latest) while installing as little as possible from conda-forge安装 somepackage 的任何版本(不一定是最新的),同时尽可能少地从 conda-forge 安装

According to the conda documentation on managing channels , one can do this by putting the conda-forge channel at the bottom of the list of channels and setting channel_priority: strict in conda's config.根据关于管理频道的 conda 文档,可以通过将conda-forge频道放在频道列表的底部并在 conda 的配置中设置channel_priority: strict来做到这一点。

With strict channel priority, packages in lower priority channels are not considered if a package with the same name appears in a higher priority channel.在严格通道优先级下,如果具有相同名称的 package 出现在较高优先级通道中,则不考虑较低优先级通道中的包。

The "manage channels" page recommends setting strict as the default and indicates that conda 5.x will set strict as the default value for channel_priority . “管理频道”页面建议将 strict 设置为默认值,并表示 conda 5.x 将设置 strict 作为channel_priority的默认值。

One can write the following to their ~/.condarc file:可以将以下内容写入他们的~/.condarc文件:

channel_priority: strict
channels:
  - defaults
  - conda-forge

However, if one uses the -c/--channel option in conda config , that channel will take precedence over any other channels.但是,如果在conda config中使用-c/--channel选项,则该通道将优先于任何其他通道。 So if one sets their conda config as above but uses conda install -c conda-forge numpy , then numpy will be installed from conda-forge .因此,如果一个人如上所述设置他们的 conda 配置但使用conda install -c conda-forge numpy ,那么numpy将从 conda conda-forge forge 安装。

Generally, I endorse the conclusion in @jakub's answer : Define a reasonable global channel priority and try to avoid using ad hoc specifications via the --channel|-c argument.一般来说,我赞同@jakub 回答中的结论:定义一个合理的全局通道优先级,并尽量避免通过--channel|-c参数使用临时规范。

There are some additional options that may be worth pointing out:还有一些其他选项可能值得指出:

  1. Specify that a particular package should come from a given channel with指定特定的 package 应该来自给定的通道

     conda install conda-forge::somepackage

    and this will not change the channel priority.这不会改变通道优先级。

  2. Explicitly list channel priorities in the install command:install命令中明确列出通道优先级:

     conda install -c defaults -c conda-forge somepackage

    which puts defaults with top priority.它将默认设置放在首位。

  3. Define and manipulate environments through YAML files.通过 YAML 文件定义和操作环境。 YAMLs include a channels section, so you can be explicit about the priority. YAML 包含一个通道部分,因此您可以明确说明优先级。 If you require a new package in the environment, it can be added to the YAML - let's say env.yaml - and that edit can be transferred to the environment with如果您在环境中需要新的 package,可以将其添加到 YAML - 比如说env.yaml - 并且可以将编辑转移到环境中

     conda env update -f env.yaml

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

相关问题 使用conda-forge包替换pip包的简便方法 - Easy way to replace pip packages with conda-forge packages 使用conda-forge强制升级软件包时有破坏anaconda python的风险吗? - Any risk of breaking anaconda python when force upgrading packages using conda-forge? 使用诗歌从 conda-forge(例如 cartopy)安装预构建包,而不依赖 conda(仅使用通道) - Install prebuilt packages from conda-forge (e.g. cartopy) using poetry without relying on conda (using only the channel) 如何使用 conda-forge 而不是 anaconda 通道安装“conda update --all”? - How to get "conda update --all" to install using conda-forge instead of anaconda channel? 将Conda更新到4.6.1以集成PowerShell后,Conda无法安装Conda-forge软件包 - Conda Not Able to Install Conda-forge Packages After Updating Conda to 4.6.1 to Integrate PowerShell 当上传者为“ conda-forge”时,更新conda-forge中的软件包 - Update package in conda-forge, when uploader is “conda-forge” Conda-Forge 与 conda-forge 存储库和安全性 - Conda-Forge vs. conda-forge repo and security pygraphviz 的 conda-forge PackagesNotFoundError - conda-forge PackagesNotFoundError for pygraphviz 从 PyPi 到 Conda-Forge - From PyPi to Conda-Forge Anaconda-是否使用通道conda-forge破坏了整个环境? - Anaconda - is using channel conda-forge screwing up the whole environment?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM