pipdeptree/README.rst

151 lines
4.0 KiB
ReStructuredText
Raw Normal View History

2014-02-02 17:42:07 +00:00
pipdeptree
==========
2014-02-05 17:29:38 +00:00
``pipdeptree`` is a command line utility for displaying the python
packages installed in an environment in form of a dependency
tree. Since ``pip freeze`` shows all dependencies as a flat list,
finding out which are the top level packages and which packages do
they depend on requires some effort. This utility tries to solve this
problem.
2014-02-05 17:29:38 +00:00
Installation
------------
.. code-block:: bash
$ pip install pipdeptree
2014-02-06 17:09:06 +00:00
.. note:: Needs to be installed inside every virtualenv
If you want to use ``pipdeptree`` to view dependency tree of packages
inside a virtualenv, then it needs to be installed inside that env
even if it's already installed globally.
2014-02-05 17:29:38 +00:00
Usage and examples
------------------
2014-02-05 17:32:50 +00:00
To give you a brief idea, here is the output of ``pipdeptree``
compared with ``pip freeze``:
2014-02-02 17:59:17 +00:00
.. code-block:: bash
$ pip freeze
Flask==0.10.1
Flask-Script==0.6.6
Jinja2==2.7.2
-e git+git@github.com:naiquevin/lookupy.git@cdbe30c160e1c29802df75e145ea4ad903c05386#egg=Lookupy-master
Mako==0.9.1
MarkupSafe==0.18
SQLAlchemy==0.9.1
Werkzeug==0.9.4
alembic==0.6.2
argparse==1.2.1
ipython==2.0.0
itsdangerous==0.23
psycopg2==2.5.2
redis==2.9.1
slugify==0.0.1
wsgiref==0.1.2
2014-02-05 17:29:38 +00:00
And now see what ``pipdeptree`` outputs,
2014-02-02 17:59:17 +00:00
.. code-block:: bash
2014-02-05 17:29:38 +00:00
$ pipdeptree
Lookupy==0.1
wsgiref==0.1.2
argparse==1.2.1
psycopg2==2.5.2
2014-02-05 17:29:38 +00:00
Flask-Script==0.6.6
- Flask [installed: 0.10.1]
- Werkzeug [required: >=0.7, installed: 0.9.4]
- Jinja2 [required: >=2.4, installed: 2.7.2]
- MarkupSafe [installed: 0.18]
- itsdangerous [required: >=0.21, installed: 0.23]
alembic==0.6.2
2014-02-05 17:29:38 +00:00
- SQLAlchemy [required: >=0.7.3, installed: 0.9.1]
- Mako [installed: 0.9.1]
- MarkupSafe [required: >=0.9.2, installed: 0.18]
ipython==2.0.0
slugify==0.0.1
redis==2.9.1
2014-02-02 17:42:07 +00:00
Using pipdeptree to write requirements.txt file
-----------------------------------------------
2014-02-05 17:29:38 +00:00
If you wish to track only the top level packages in your
2014-05-10 19:02:26 +00:00
``requirements.txt`` file, it's possible to do so using ``pipdeptree``
by grep-ing only the top-level lines from the output,
.. code-block:: bash
$ pipdeptree | grep -P '^\w+'
Lookupy==0.1
wsgiref==0.1.2
argparse==1.2.1
psycopg2==2.5.2
Flask-Script==0.6.6
alembic==0.6.2
ipython==2.0.0
slugify==0.0.1
redis==2.9.1
There is a problem here though. The output doesn't mention anything
2014-05-10 19:02:26 +00:00
about ``Lookupy`` being installed as an editable package (refer to the
output of ``pip freeze`` above) and information about it's source is
lost. To fix this, ``pipdeptree`` must be run with a ``-f`` or
``--freeze`` flag.
2014-02-05 17:29:38 +00:00
.. code-block:: bash
2014-02-02 17:42:07 +00:00
$ pipdeptree -f | grep -P '^[\w0-9\-=.]+'
-e git+git@github.com:naiquevin/lookupy.git@cdbe30c160e1c29802df75e145ea4ad903c05386#egg=Lookupy-master
2014-02-05 17:29:38 +00:00
wsgiref==0.1.2
argparse==1.2.1
psycopg2==2.5.2
Flask-Script==0.6.6
alembic==0.6.2
ipython==2.0.0
2014-02-05 17:29:38 +00:00
slugify==0.0.1
redis==2.9.1
2014-05-10 19:02:26 +00:00
$ $ pipdeptree -f | grep -P '^[\w0-9\-=.]+' > requirements.txt
2014-02-02 17:42:07 +00:00
Usage
-----
2014-02-05 17:29:38 +00:00
.. code-block:: bash
2014-05-10 19:02:26 +00:00
usage: pipdeptree.py [-h] [-f] [-a] [-l]
2014-02-05 17:29:38 +00:00
Dependency tree of the installed python packages
optional arguments:
-h, --help show this help message and exit
2014-05-10 19:02:26 +00:00
-f, --freeze Print names so as to write freeze files
2014-02-05 17:29:38 +00:00
-a, --all list all deps at top level
2014-02-08 05:26:52 +00:00
-l, --local-only If in a virtualenv that has global access donot show
globally installed packages
2014-02-05 17:29:38 +00:00
Known Issues
------------
One thing you might have noticed already is that ``flask`` is shown as
a dependency of ``flask-script``, which although correct, sounds a bit
odd. ``flask-script`` is being used here *because* we are using
``flask`` and not the other way around. Same with ``sqlalchemy`` and
``alembic``. I haven't yet thought about a possible solution to this!
(May be if libs that are "extensions" could be distinguished from the
ones that are "dependencies". Suggestions are welcome.)
2014-02-02 17:42:07 +00:00
License
-------
2014-02-05 17:29:38 +00:00
MIT (See LICENSE)