18

I have a requirements.txt like

numpy

and an environment.yml containing

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

when I then run conda env create --file environment.yml I get

Pip subprocess output:

Pip subprocess error: ERROR: Exception:

<... error traceback in pip >

AttributeError: 'FileNotFoundError' object has no attribute 'read'

failed

CondaEnvException: Pip failed

It is also strange how pip is called, as reported just before the error occurs:

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

(I replace my home path with $HOME) Note the weird expansion of the requirements.txt.

Any ideas?

Stefan
  • 1,697
  • 15
  • 31
  • That command at the end is normal: Conda takes the whole `pip:` section and translates it to a temporary `requirements.txt` and the explicit `-r file:requirements.txt` will be nested inside that file (see [this code](https://github.com/conda/conda/blob/33a142c16530fcdada6c377486f1c1a385738a96/conda_env/installers/pip.py#L19)). Is the directory (`$HOME/test`) writable? I.e., perhaps Conda is having trouble generating the temporary file? If you just do `- numpy` under the `pip:` section does it work? – merv Jul 29 '21 at 18:17
  • 1
    @merv Yes, `$HOME/test` is writable. Yes, replacing `-r file:requirements.txt` with `- numpy` works just fine. – Stefan Jul 30 '21 at 05:10

1 Answers1

27

Changes to Pip Behavior in 21.2.1

A recent change in the Pip code has changed its behavior to be more strict with respect to file: URI syntax. As pointed out by a PyPA member and Pip developer, the syntax file:requirements.txt is not a valid URI according to the RFC8089 specification.

Instead, one must either drop the file: scheme altogether:

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

or provide a valid URI, which means using an absolute path (or a local file server):

name: test
dependencies:
  - python>=3
  - pip
  - pip:
    - -r file:/full/path/to/requirements.txt
    # - -r file:///full/path/to/requirements.txt # alternate syntax
merv
  • 67,214
  • 13
  • 180
  • 245