Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pip Install -r continue past installs that fail

I am installing a list of packages with pip-python using the command

pip install -r requirements.txt 

sometimes it fails installing packages for whatever reason. Is it possible to have it continue the the next package even with these failures?

like image 753
JiminyCricket Avatar asked Jun 23 '11 16:06

JiminyCricket


People also ask

What to do if pip install fails?

Trying to fix PIP or you could just try and install pip from scratch by doing the following. Copy the code from get-pip.py or save the file from the link. Then simply run the file with python. This should install pip for you and get it working.

Why is pip installing old version?

For example, you may need to install an older version of a package if the package has changed in a way that is not compatible with the version of Python you have installed, with other packages that you have installed, or with your Python code.

How do I clear my pip cache?

If you want to force pip to clear out its download cache and use the specific version you can do by using --no-cache-dir command. If you are using an older version of pip than upgrade it with pip install -U pip. This will help you clear pip cache.


2 Answers

I have the same problem. continuing on the line of @Greg Haskins, maybe this bash one-liner is more succinct:

cat requirements.txt | while read PACKAGE; do pip install "$PACKAGE"; done  # TODO: extend to make the script print a list of failed installs, # so we can retry them. 

(for the non-shellscripters: it calls pip install for each of the listed packages)

the same note on the dependancies failure applies of course here!

like image 110
caesarsol Avatar answered Sep 28 '22 04:09

caesarsol


You could write a little wrapper script to call pip iteratively, something like:

#!/usr/bin/env python """ pipreqs.py: run ``pip install`` iteratively over a requirements file. """ def main(argv):     try:         filename = argv.pop(0)     except IndexError:         print("usage: pipreqs.py REQ_FILE [PIP_ARGS]")     else:         import pip         retcode = 0         with open(filename, 'r') as f:             for line in f:                 pipcode = pip.main(['install', line.strip()] + argv)                 retcode = retcode or pipcode         return retcode if __name__ == '__main__':     import sys     sys.exit(main(sys.argv[1:])) 

which you could call like pipreqs.py requirements.txt --some --other --pip --args.

Note that this only applies the "continue despite failure" motto one level deep---if pip can't install a sub-requirement of something listed, then of course the parent requirement will still fail.

like image 43
Greg Haskins Avatar answered Sep 28 '22 06:09

Greg Haskins