Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically check if Python dependencies are satisfied

I'd like to programmatically run pip and determine whether the current virtualenv environment complies with a specified requirements.txt file. I'm not fussed about running pip or anything, but I thought since it can read requirements.txt-like files, it would be a good start.

However, I haven't even found a way of effectively running pip from the command line. pip install -r requirements.txt --no-install was suggested somewhere, but it downloads each package and even if this wasn't a problem, I am unsure of how to interpret its output as to whether or not all dependencies are satisfied.

like image 480
orange Avatar asked Mar 06 '14 03:03

orange


People also ask

How do I check Python package dependencies?

Instead, package dependencies can be seen using one of the following commands in Python: pip show: List dependencies of Python packages that have already been installed. pipdeptree: List the dependencies in a tree form. Pip list: List installed packages with various conditions.

How do I know if a Python package is compatible?

If you are using an older version of Python and need the most recent version of the package that is compatible with that version, you can go to the release history (the second link at the top of the sidebar) and try different versions, scrolling down to the "Meta" section for every version.


1 Answers

This post has a lot of good suggestions for getting a list of modules. You can use the below code to print out all missing modules:

from pkgutil import iter_modules
modules = set(x[1] for x in iter_modules())

with open('requirements.txt', 'rb') as f:
    for line in f:
        requirement = line.rstrip()
        if not requirement in modules:
            print requirement
like image 180
James Mnatzaganian Avatar answered Oct 25 '22 01:10

James Mnatzaganian