如何限制conda中的软件包版本? [英] How to constrain package versions in conda?

查看:2023
本文介绍了如何限制conda中的软件包版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在conda环境中工作,该环境中预装了一堆软件包(conda列表中包含360个软件包,许多ML工具和一些bioconda).有时我需要添加一个程序包;但是,我发现 conda install newpackage 通常非常慢(在解决环境"中花费了数小时或数天),并且如果完成了,它通常建议更新我确实不想要的软件包触摸.

I'm working in a conda environment with a bunch of packages preinstalled (conda list has 360 packages, a lot of ML tools and some bioconda). I sometimes need to add a package; however, I find that conda install newpackage is often extremely slow (hours or days spent at "Solving environment"), and if it ever finishes, it often suggests updates to packages I really don't want to touch.

我想固定一些核心软件包(python,numpy,scipy等)的当前版本,以便conda甚至都无法修改它们.这既是为了提高速度,又是为了避免意外更新.如果那意味着我想尝试添加的某个软件包无法安装,那就可以了!我宁愿有一个快速的答案,例如"newpackage与您的numpy版本冲突".比没有答案.然后,我可以决定是否要忽略冲突.仅为此一个程序包创建一个简单的环境;conda在本地或其他任何地方构建.

I'd like to pin the current versions of some of the core packages (python, numpy, scipy, etc) so that modifying them isn't even considered possible by conda. This is both for speed, and to avoid any unintentional updates. If that means a certain package I want to try adding can't be installed, that's okay! I'd much rather have a quick answer like "newpackage conflicts with your version of numpy" than no answer. I can then decide if I want to ignore the conflict; make a simple environment just for this one package; conda build locally, or whatever.

我该怎么做?

另请参阅: https://www.anaconda.com/博客/了解并改善condas性能(无法解决问题)

See also: https://www.anaconda.com/blog/understanding-and-improving-condas-performance (which didn't solve the problem)

推荐答案

打包固定

可以根据每个环境将软件包固定到特定版本.请参见

Package Pinning

Packages can be pinned to specific versions on a per-environment basis. See the documentation on package pinning. For example, suppose we want to pin numpy and scipy to the exact versions we currently have in an env called foo. We could process the output of conda list to match the expected syntax of the Conda pinning specification:

conda activate foo
conda list "^(numpy|scipy)$" | tail -n+4 | awk '{ print $1 " ==" $2 }' > $CONDA_PREFIX/conda-meta/pinned

这里需要注意的几件事:

A few things to note here:

  • conda列表使用正则表达式:利用它来发挥优势
  • tail 只是跳过标题
  • 这取决于在激活的环境中定义 $ CONDA_PREFIX
  • 这会覆盖任何现有的 pinned 文件
  • conda list takes a regex: use that to your advantage
  • tail is just to skip the header
  • this depends on being in the activated env to define $CONDA_PREFIX
  • this overwrites any existing pinned file

使用较少的劳动强度方法来使所有内容保持不变是使用-freeze-installed 标志.但是,在较新版本的Conda中,默认情况下在第一轮求解中使用此功能.因此,实际上,此标志现在所做的所有事情就是跳过第二轮求解,从而允许更新不属于显式规范的软件包.

A less labor intensive means of keeping everything constant is to use the --freeze-installed flag. However, in more recent versions of Conda this is used by default in the first round of solving. So really all this flag does now is to skip the second round of solving that allows for packages that are not part of the explicit specifications to be updated.

这篇关于如何限制conda中的软件包版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆