Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skipping error when installing packaging using PIP

Tags:

python

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)
like image 352
Prometheus Avatar asked May 19 '14 14:05

Prometheus


People also ask

Why I cant install packages in Python?

The first reason that prevents you from installing the latest package versions is dependency error. A possible solution is to check the latest versions of the package and to install one which is: supported by your version. doesn't have dependency issues.

What can I use instead of pip to install?

There are a number of alternatives to pip that you may want to try. Conda is the package and environment manager that comes bundled with Anaconda. Conda has its own package repository that can be used to install Python packages into a Conda virtual environment.


1 Answers

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.

like image 138
philshem Avatar answered Sep 28 '22 19:09

philshem