在Conda YML文件中使用pip要求文件会引发AttributeError:'FileNotFoundError'

2022-03-12 python conda pip

问题描述

我有一个requirements.txt

numpy

和包含

environment.yml
# run via: conda env create --file environment.yml
---
name: test
dependencies:
  - python>=3
  - pip
  - pip:
      - -r file:requirements.txt

当我随后运行conda env create --file environment.yml时,我收到

Pip子进程输出:

Pip子进程错误: 错误:异常:

<;.PIP>;中的错误回溯

AttributeError:"FileNotFoundError"对象没有属性""Read""

失败

CondaEnvException:PIP失败

调用pip的方式也很奇怪,就像错误发生前报告的那样:

['$HOME/.conda/envs/test/bin/python', '-m', 'pip', 'install', '-U', '-r', '$HOME/test/condaenv.8d3003nm.requirements.txt']

(我将我的主路径替换为$HOME) 注意requirements.txt的奇怪扩展。

有什么想法吗?


解决方案

21.2.1中对管道行为的更改

A recent change in the Pip code已将其行为更改为在file:URI语法方面更加严格。As pointed out由Pypa成员和Pip开发人员根据the RFC8089 specification,语法file:requirements.txt不是有效的URI。

相反,必须完全放弃file:方案:

name: test
dependencies:
  - python>=3
  - pip
  - pip:
    - -r requirements.txt

或提供有效的URI,即使用绝对路径(或本地文件服务器):

name: test
dependencies:
  - python>=3
  - pip
  - pip:
    - -r file:/full/path/to/requirements.txt
    # - -r file:///full/path/to/requirements.txt # alternate syntax

相关文章