When I do a pip freeze I see large number of Python packages that I didn't explicitly install, e.g.
$ pip freeze
Cheetah==2.4.3
GnuPGInterface==0.3.2
Landscape-Client==11.01
M2Crypto==0.20.1
PAM==0.4.2
PIL==1.1.7
PyYAML==3.09
Twisted-Core==10.2.0
Twisted-Web==10.2.0
(etc.)
Is there a way for me to determine why pip installed these particular dependent packages? In other words, how do I determine the parent package that had these packages as dependencies?
For example, I might want to use Twisted and I don't want to depend on a package until I know more about not accidentally uninstalling it or upgrading it.
You may also use a one line command which pipes the packages in requirements to pip show.
(workaround, not true answer)
Had the same problem, with lxml not installing and me wanting to know who needed lxml. Not who lxml needed. Ended up bypassing the issue by.
noting where my site packages were being put.
go there and recursive grep for the import (the last grep's --invert-match serves to remove lxml's own files from consideration).
Yes, not an answer as to how to use pip to do it, but I didn't get any success out of the suggestions here, for whatever reason.
The
pip show
command will show what packages are required for the specified package (note that the specified package must already be installed):pip show
was introduced in pip version 1.4rc5You could try pipdeptree which displays dependencies as a tree structure e.g.:
To get it run:
EDIT: as noted by @Esteban in the comments you can also list the tree in reverse with
-r
or for a single package with-p <package_name>
so to find what installed Werkzeug you could run:First of all
pip freeze
displays all currently installed packages Python, not necessarily using PIP.Secondly Python packages do contain the information about dependent packages as well as required versions. You can see the dependencies of particular pkg using the methods described here. When you're upgrading a package the installer script like PIP will handle the upgrade of dependencies for you.
To solve updating of packages i recommend using PIP requirements files. You can define what packages and versions you need, and install them at once using pip install.
As I recently said on a hn thread, I'll recommend the following:
Have a commented
requirements.txt
file with your main dependencies:Install your dependencies:
pip install -r requirements.txt
. Now you get the full list of your dependencies withpip freeze -r requirements.txt
:This allows you to keep your file structure with comments, nicely separating your dependencies from the dependencies of your dependencies. This way you'll have a much nicer time the day you need to remove one of them :)
Note the following:
requirements.raw
with version control to rebuild your fullrequirements.txt
.pip install --no-install <package_name>
to list specific requirements.