Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I specify a pip find-links option in a conda environment file?

Tags:

pip

conda

I have a pip requirements file that includes specific cpu-only versions of torch and torchvision. I can use the following pip command to successfully install my requirements.

pip install --requirement azure-pipelines-requirements.txt --find-links https://download.pytorch.org/whl/torch_stable.html

My requirements file looks like this

coverage
dataclasses
joblib
matplotlib
mypy
numpy
pandas
param
pylint
pyro-ppl==1.2.1
pyyaml
scikit-learn
scipy
seaborn
torch==1.4.0+cpu
torchvision==0.5.0+cpu 
visdom

This works from bash, but how do I invoke pip with the find-links option from inside a conda environment yaml file? My current attempt looks like this

name: build  
dependencies:  
  - python=3.6  
  - pip  
  - pip:  
    - --requirement azure-pipelines-requirements.txt --find-links https://download.pytorch.org/whl/torch_stable.html  

But when I invoke

conda env create --file azure-pipeline-environment.yml

I get this error.

Pip subprocess error:
ERROR: Could not find a version that satisfies the requirement torch==1.4.0+cpu (from -r E:\Users\tim\Source\Talia\azure-pipelines-requirements.txt (line 25)) (from versions: 0.1.2, 0.1.2.post1, 0.1.2.post2)
ERROR: No matching distribution found for torch==1.4.0+cpu (from -r E:\Users\tim\Source\Talia\azure-pipelines-requirements.txt (line 25))

CondaEnvException: Pip failed

How do I specify the find-links option when invoking pip from a conda environment yaml file?

like image 489
dumbledad Avatar asked Feb 26 '20 09:02

dumbledad


People also ask

Can I use pip in a conda environment?

You can install pip in the current conda environment with the command conda install pip , as discussed in Using pip in an environment. If there are instances of pip installed both inside and outside the current conda environment, the instance of pip installed inside the current conda environment is used.

How does conda work with pip?

In short, pip is a general-purpose manager for Python packages; conda is a language-agnostic cross-platform environment manager. For the user, the most salient distinction is probably this: pip installs python packages within any environment; conda installs any package within conda environments.

Where does conda pip install packages?

It should be somewhere like /anaconda/envs/venv_name/ . Install new packages by doing /anaconda/envs/venv_name/bin/pip install package_name .


2 Answers

This example shows how to specify options for pip

Specify the global pip option first:

name: build  
dependencies:  
  - python=3.6  
  - pip  
  - pip:
    - --find-links https://download.pytorch.org/whl/torch_stable.html
    - --requirement azure-pipelines-requirements.txt  
like image 130
FlyingTeller Avatar answered Nov 23 '22 23:11

FlyingTeller


Found the answer in the pip documentation here. I can add the find-links option to my requirements file, so my conda environment yaml file becomes

name: build
dependencies:
  - python=3.6
  - pip
  - pip:
    - --requirement azure-pipelines-requirements.txt

and my pip requirements file becomes

--find-links https://download.pytorch.org/whl/torch_stable.html
coverage
dataclasses
joblib
matplotlib
mypy
numpy
pandas
param
pylint
pyro-ppl==1.2.1
pyyaml
scikit-learn
scipy
seaborn
torch==1.4.0+cpu
torchvision==0.5.0+cpu 
visdom
like image 44
dumbledad Avatar answered Nov 23 '22 23:11

dumbledad