Skip to content
Advertisement

Upgrading pip to latest version using pip in conda using environment.yaml

I am trying to create an environment using environment.yaml, and for some reason the default pip installed in my environment by conda takes a long time to process the dependencies.

For this reason, I am trying to somehow upgrade the pip version in the conda envrionment file.

name: temp_env
channels:
  - pytorch
  - defaults
dependencies:
  - python=3.7
  - pytorch::pytorch=1.11.0
  - pytorch::torchvision=0.12.0
  - pytorch::cpuonly
  - pip
  - pip: 
      - -e '.[dev]'

The pip version that comes with this installation is pip 21.2.2 . I am trying to upgrade pip to latest version which as of now is 22.0.4. I can write a bash script to install the conda environment without the pip parts first and then install the package in it, but this is less than ideal. I’m trying to come up with a solution only using the YAML file.

I tried this:

  - pip>=22.0.4
  - pip: 
      - -e '.[dev]'

But apparently this version does not exist yet on conda’s main channels. I also tried:

  - pip
  - pip:
    - -U pip
    - -e '.[dev]'

But this also does not work and throws an error.

[‘/path/to/miniconda3/envs/temp_env/bin/python’, ‘-m’, ‘pip’, ‘install’, ‘-U’, ‘-r’, ‘/path/to/folder/condaenv.0kdmzdvh.requirements.txt’]

Pip subprocess error: ERROR: Invalid requirement: “pip ‘-U'”

Advertisement

Answer

The conda-forge channel has it. So,

name: temp_env
channels:
  - pytorch
  - conda-forge
dependencies:
  - python=3.7
  - pytorch::pytorch=1.11.0
  - pytorch::torchvision=0.12.0
  - pytorch::cpuonly
  - pip>=22.0.4
  - pip: 
      - -e '.[dev]'

Also, as can be seen in the error, when Conda runs the pip install command, it already adds a -U. However, the main issue is that for one to upgrade pip and then use that upgraded pip would mean running two sequential pip install commands, which one cannot do from the YAML alone. Everything in the pip: list is copied to a requirements.txt and effectively passed to pip install -U as one directive.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement