13

I run pip

pip install -r /requirements.txt

If one of my packages fails the whole things aborts and no other packages would get installed.

Is there a command that in the event of an error it will continue to install the next package?

So for my usecase: here is what I do using a fab file:

def _install_requirements():
    """
    Installs the required packages from the requirements.txt file using pip.
    """

    if not exists(config.SERVER_PROJECT_PATH + '/requirements.txt', use_sudo=True):
        print('Could not find requirements')
        return
    sudo('pip install -r %s/requirements.txt' % SERVER_PROJECT_PATH)
Prometheus
  • 32,405
  • 54
  • 166
  • 302
  • I don't think this is possible with pip. It wouldn't make too much sense, now would it? I mean, what's the point of installing something if it depends on another package that didn't install correctly? Both wouldn't work anyway – yuvi May 19 '14 at 14:27
  • 2
    For my use case it would, I install my requirements via a fab file on the server and one error stops the whole thing from continuing on. – Prometheus May 19 '14 at 14:28
  • 3
    Have you tried a `for` loop with a try/except block? – kylieCatt May 19 '14 at 14:31
  • 1
    Possible duplicate of [Stop pip from failing on single package when installing with requirements.txt](http://stackoverflow.com/questions/22250483/stop-pip-from-failing-on-single-package-when-installing-with-requirements-txt) – obskyr Jun 27 '16 at 13:30

1 Answers1

4

There is a handy python script for updating all libraries with pip (source):

import pip
from subprocess import call

for dist in pip.get_installed_distributions():
    call("pip install --upgrade " + dist.project_name, shell=True)

In the 'for' loop you can loop over the requirements.

# read requirements.txt file, create list of package names
for package in requirements:
    call("pip install " + package, shell=True)

This won't crash if you can't install a package.

Community
  • 1
  • 1
philshem
  • 24,761
  • 8
  • 61
  • 127