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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With