Conda安装冲突要求

发布于 2025-01-31 16:17:02 字数 409 浏览 1 评论 0原文

我正在尝试使用CONDA来创建PIP需求文件的环境。文件的内容为

supports.txt

numpy==1.18.2
torch==1.4.0
torchvision==0.5.0
scikit-learn==0.22.2.post1
Pillow==8.3.2
pydicom==1.4.2
pandas==1.0.3

运行该命令

conda create -n $name --file requirements.txt

给出packagenotfound错误,因为缺少频道。

我该如何修改这个?

I am attempting to use Conda to create an environment from a Pip requirements file. The contents of the file are

requirements.txt

numpy==1.18.2
torch==1.4.0
torchvision==0.5.0
scikit-learn==0.22.2.post1
Pillow==8.3.2
pydicom==1.4.2
pandas==1.0.3

Running the command

conda create -n $name --file requirements.txt

gives a PackageNotFound error as the channels are missing.

How do I amend this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗喜 2025-02-07 16:17:02

可能的问题

存在一些潜在的问题。

conda pytorch

首先,并非conda中的所有软件包都以与其他存储库相同的名称使用。部分原因是Conda是一个通用软件包存储库的性质,而不是特定于语言的存储库。特别是,火炬模块是通过conda pytorch软件包传递的。

因此必须改变。

numpy版本不可用,

默认值 conda-forge 频道似乎都不可用。

$ mamba search numpy=1.18.2
No match found for: numpy=1.18.2. Search: *numpy*=1.18.2

PackagesNotFoundError: The following packages are not available from current channels:

  - numpy=1.18.2

Current channels:

  - https://conda.anaconda.org/conda-forge/osx-64
  - https://conda.anaconda.org/conda-forge/noarch
  - https://conda.anaconda.org/bioconda/osx-64
  - https://conda.anaconda.org/bioconda/noarch
  - https://repo.anaconda.com/pkgs/main/osx-64
  - https://repo.anaconda.com/pkgs/main/noarch
  - https://repo.anaconda.com/pkgs/r/osx-64
  - https://repo.anaconda.com/pkgs/r/noarch

为什么会发生这种情况?对于大多数Python包装,Conda都在PYPI存储库的下游工作。当新版本发布时,Conda Forge机器人(例如)将自动生成相应的原料请求。有时,这些不仅仅是“工作”,需要进行一些故障排除才能构建。有时,使构建工作正常工作的过程不会在新版本命中之前完成。这导致了一个较新的拉力请求,将上一个请求取代,并可能导致放弃旧的拉力请求。这会导致Conda Forge的PYPI覆盖范围,并且IS 确切发生了什么在这里

如果您可以忍受其他版本, conda-forge 确实提供v1.18.1(下图)和v1.18.4(上图)。

否则,如果您需要精确复制软件包版本,则必须从PYPI中源。我最后显示。

频道问题

缺少通道

OP不会指示通道配置。例如,torchvision == 0.5.0软件包,仅通过 pytorch 频道可用。

蒙版通道

这里的另一个问题可能是使用channel_priority:strict设置。如果使用此设置,则可能仅仅是因为SAT求解器排除了所需版本的频道,仅仅是因为软件包(但不正确的版本)可以在较高的优先级频道中提供。如今,channel_priority:flexible是默认值,可以设置:

conda config --set channel_priority flexible

解决方案

精确复制(仅PYPI)

给出包装名称和版本,这些软件包可能起源于PYPI。如果您需要精确复制原始环境(例如,为了再现科学结果),我建议您从PYPI中采购所有内容。最好的方法是使用conda来源python和pip,然后让pip安装unignts.txt

从包装版本来看,我们正在谈论Python 3.7或3.8。只需python = 3.8,您可能会很好,但是[精确的猜测来自发布日期将是python = 3.8.2。因此,尝试类似的内容:

emoverument.yaml

name: my_env
channels:
  - conda-forge
dependencies:
  - python=3.8.2
  - pip
  - pip:
    - -r requirements.txt

创建环境

conda env create -n $name -f environment.yaml

,然后通过确保support.txt在使用YAML的文件夹中

。如果稍后将软件包添加到此环境中,我建议仅使用pip install。否则, conda可能有问题

/

假设numpy = 1.18.2可以替换,只有conda的环境可以替换,仅conda的环境可能是:

emoveration.yaml <

name: my_env
channels:
  - pytorch
  - conda-forge
dependencies:
  - python=3.8
  - numpy=1.18.1  # alternatively, 1.18.4
  - pytorch=1.4.0
  - torchvision=0.5.0
  - scikit-learn=0.22.2.post1
  - pillow=8.3.2
  - pydicom=1.4.2
  - pandas=1.0.3

strong ,请注意:

conda env create -n $name -f environment.yaml

请注意: yaml仅使用一个=。如果您打算以 ad hoc 方式通过conda安装其他软件包(例如,conda install),这将是最好的方法。

混合的conda-pip环境

您也可以尝试一个与最后一个环境相似的混合环境,但是PIP专门提供numpy == 1.18.2。我不建议这样做,因为其他带有Conda的numpy的依赖性肯定会带来Numpy,然后PIP会抓住它以提供确切的版本。

Possible Issues

There are a few potential issues.

Conda pytorch

First, not all packages in Conda go by the same name as they do in other repositories. Part of this is due to the nature of Conda being a general package repository, rather than a language-specific one. In particular, the torch module is delivered via the Conda pytorch package.

So that has to change.

NumPy version unavailable

That particular build of NumPy does not appear to be available in either defaults or conda-forge channels.

$ mamba search numpy=1.18.2
No match found for: numpy=1.18.2. Search: *numpy*=1.18.2

PackagesNotFoundError: The following packages are not available from current channels:

  - numpy=1.18.2

Current channels:

  - https://conda.anaconda.org/conda-forge/osx-64
  - https://conda.anaconda.org/conda-forge/noarch
  - https://conda.anaconda.org/bioconda/osx-64
  - https://conda.anaconda.org/bioconda/noarch
  - https://repo.anaconda.com/pkgs/main/osx-64
  - https://repo.anaconda.com/pkgs/main/noarch
  - https://repo.anaconda.com/pkgs/r/osx-64
  - https://repo.anaconda.com/pkgs/r/noarch

Why would this happen? For most Python packages, Conda works downstream of the PyPI repository. When new releases come out, the Conda Forge bot (for example) will auto-generate a pull request to corresponding feedstock. Sometimes these don't "just work" and need some troubleshooting to get built. Occasionally, the process to get the builds working won't finish before a new release hits. This results in a newer pull request superceding the previous one, and can lead to the old pull request being abandoned. This results in gaps in the coverage of PyPI by Conda Forge, and is exactly what happened here.

If you can tolerate a different version, conda-forge does provide v1.18.1 (below) and v1.18.4 (above).

Otherwise, if you require exact replication of package versions, then you will have to source this from PyPI. I'll show this in the end.

Channel issues

Missing channels

OP does not indicate the channel configuration. The torchvision==0.5.0 package, for example, only is available through the pytorch channel.

Masked channels

Another issue here could be the use of the channel_priority: strict setting. If this setting were used, it is possible a channel with the version required might be a priori excluded by the SAT solver simply because the package (but not the correct version) is available in a higher priority channel. These days channel_priority: flexible is the default and can be set with:

conda config --set channel_priority flexible

Solutions

Exact replication (PyPI only)

Give the package names and versions, these packages likely originated from PyPI. If you need to exactly replicate the original environment - say, for reproducing scientific results - then I'd recommend sourcing everything from PyPI. The best way to do this is to use Conda to source Python and Pip, then let Pip install the requirements.txt.

Judging from the package versions, we're talking Python 3.7 or 3.8. You'd probably be fine with just python=3.8, but [a precise guesstimate from release dates would be python=3.8.2. So, try something like:

environment.yaml

name: my_env
channels:
  - conda-forge
dependencies:
  - python=3.8.2
  - pip
  - pip:
    - -r requirements.txt

Then create the environment with

conda env create -n $name -f environment.yaml

making sure the requirements.txt is in the folder with the YAML.

If adding packages to this environment later, I would recommend only using pip install. Otherwise, Conda may have issues.

Conda-only environment

Assuming the numpy=1.18.2 can be substituted, a Conda-only environment might be something like:

environment.yaml

name: my_env
channels:
  - pytorch
  - conda-forge
dependencies:
  - python=3.8
  - numpy=1.18.1  # alternatively, 1.18.4
  - pytorch=1.4.0
  - torchvision=0.5.0
  - scikit-learn=0.22.2.post1
  - pillow=8.3.2
  - pydicom=1.4.2
  - pandas=1.0.3

Again, creating with:

conda env create -n $name -f environment.yaml

Note that in YAML only one = is used. This would be the best approach if you plan to install additional packages through Conda in an ad hoc manner (e.g., conda install).

Mixed Conda-Pip environment

You could also try a mixed environment mostly similar to the last one, but having Pip specifically provide numpy==1.18.2. I wouldn't recommend this, since the other dependencies with definitely bring in NumPy first from Conda, and then Pip will clobber it to provide the exact version.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文