Question
Asked By – cdeepakroy
While installing packages in requirements.txt using Conda through the following command
conda install --yes --file requirements.txt
If a package in requirements.txt is not available, then it throws a “No package error” such as the one shown below:
Using Anaconda Cloud api site https://api.anaconda.org
Fetching package metadata: ….
Error: No packages found in current linux-64 channels matching: nimfa ==1.2.3
You can search for this package on anaconda.org with
anaconda search -t conda nimfa ==1.2.3
Instead of throwing an error, is it possible to change this behavior such that it installs all the available packages in requirements.txt and throws a warning for those that are not available?
I would like this because, the package nimfa which the error says is not available, can be pip installed. So if I can change the behavior of conda install --yes --file requirements.txt
to just throw a warning for unavailable packages, I can follow it up with the command pip install -r requirments.txt
in .travis.yml so TravisCI attempts to install it from either place where it is available.
Now we will see solution for issue: Install only available packages using “conda install –yes –file requirements.txt” without error
Answer
I ended up just iterating over the lines of the file
$ while read requirement; do conda install --yes $requirement; done < requirements.txt
Edit: If you would like to install a package using pip if it is not available through conda, give this a go:
$ while read requirement; do conda install --yes $requirement || pip install $requirement; done < requirements.txt
Edit: If you are using Windows (credit goes to @Clay):
$ FOR /F "delims=~" %f in (requirements.txt) DO conda install --yes "%f" || pip install "%f"
This question is answered By – Till Hoffmann
This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0