How to view PIP dependencies using pipdeptree

When you install a Python PIP package using the pip tool, you will notice that it figures out if the package depends on other packages and installs them too. It is sometimes useful to know what is this tree of packages that a package depends on. pipdeptree is a tool that makes it easy to view this information.

  • Installing pipdeptree is easy:
$ sudo pip3 install pipdeptree
  • View the dependency tree of every installed package
$ pipdeptree
  • View the dependency tree of a particular package foobar:
$ pipdeptree -p foobar
  • View the reverse dependency tree — the packages that are dependent on every installed package:
$ pipdeptree -r
  • Render the dependency tree graph to a PDF file using GraphViz:
$ pipdeptree --graph-output pdf > out.pdf

Tried with: Ubuntu 18.04

Cannot import name main


I got this error when I tried running pip:

    from pip import main
ImportError: cannot import name 'main'


I had installed pip from Ubuntu repositories using this command:

$ sudo apt install python-pip

However, I had previously used a pip from Anaconda on this computer. Though I had uninstalled it, it looked like it had left some files that were affecting how the Ubuntu pip worked.

I found the ~/.local/bin and ~/.local/lib directories that Anaconda pip had created and deleted those directories. Ubuntu pip worked fine after that.

Tried with: Ubuntu 16.04

Pip uninstall error


I had installed a package using Pip. However, when I tried to uninstall it, I got this error:

$ sudo pip uninstall h5py
Can't uninstall 'h5py'. No files were found to uninstall.


You first want to make sure that you are using the pip version that matches the package. That is, if you installed a Python 2.x package, that can only be uninstalled using pip. A Python 3.x package can only be uninstalled using pip3.

In my case, I could not discover the real reason for this error, I resorted to finding the deleting the installed directory for this package. I found the directory h5py-2.6.0-py2.7.egg-info under /usr/local/lib/python2.7/dist-packages and deleted that. If this was a Python 3.x package, I would similarly have looked under the /usr/local/lib/python3.x/ directory.

Tried with: Ubuntu 14.04

How to open IPython Notebook file

The .ipynb file is an IPython Notebook file containing the Python commands, output and notes that another user has recorded.

To be able to create or open this file, we need to install IPython and its notebook package:

$ sudo apt install ipython-notebook

After installation, it is invoked as:

$ ipython notebook

This open a Mathematica-like web interface in your browser. You can create new IPython Notebook files or open existing files for viewing.

On a recent IPython Notebook file, I got this error when I opened it:

Error loading notebook
Unreadable Notebook: Unsupported JSON nbformat version 4 (supported version: 3)

This means that a more recent version of notebook package needs to be used to open this file. More confusingly, the notebook package has been moved into a new project called Jupyter. Since this is a new development its package was not available on my ancient Ubuntu.

I installed it from PyPI using:

$ sudo pip3 install jupyter

To open its notebook web interface:

$ jupyter-notebook

I was able to open the problematic IPython Notebook file correctly using this.

Tried with: Jupyter 4.x and Ubuntu 14.04

Pip ImportError on IncompleteRead


I was using the Pip from the Ubuntu repositories, installed using the package python-pip. I upgraded some Python packages using Pip and after one of them failed, invoking pip for any command gave this ImportError on the name IncompleteRead:

$ pip list
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    load_entry_point('pip==1.5.4', 'console_scripts', 'pip')()
  File "/usr/lib/python2.7/dist-packages/", line 351, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/dist-packages/", line 2363, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/dist-packages/", line 2088, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/usr/lib/python2.7/dist-packages/pip/", line 61, in <module>
    from pip.vcs import git, mercurial, subversion, bazaar  # noqa
  File "/usr/lib/python2.7/dist-packages/pip/vcs/", line 9, in <module>
    from import path_to_url
  File "/usr/lib/python2.7/dist-packages/pip/", line 25, in <module>
    from requests.compat import IncompleteRead
ImportError: cannot import name IncompleteRead


The Pip from Ubuntu can be very old and trails the packages a lot. This problem went away when I removed this Pip and installed the latest one from PyPI:

$ sudo apt remove python-pip
$ sudo easy_install pip

Tried with: Pip 1.5.4 (old) and 7.1.0 (new) and Ubuntu 14.04

How to upgrade all installed Pip packages

Pip makes it convenient to install Python programs and modules from PyPI. One problem that I face with it is to upgrade all my installed packages.

  • pip help install seems to indicate that the --upgrade will upgrade all installed packages. But in reality it does not.

  • One way to solve this is to install the pip-tools package:

$ sudo pip install pip-tools
  • This package provides a pip-review tool that can be used to upgrade all installed packages:
$ sudo pip-review --auto --verbose

Tried with: pip-tools 0.3.6, Pip 7.1.0, Python 2.7.6 and Ubuntu 14.04

pip cheatsheet

Installing and managing packages of Python is a pain. Many popular Python packages are available for installation from Ubuntu repositories, but they are old versions.

The most convenient way to install, uninstall and manage Python packages is Pip.

  • pip is the usually the Python2 tool. pip3 is the Python3 tool. All the commands in this post will use pip, but they apply the same to pip3.

  • pip and pip3 can be installed from Ubuntu repositories:

$ sudo apt install python-pip python3-pip
  • To install a package from PyPI for all users:
$ sudo pip install foobar

This installs the package files to /usr/local/lib/python2.x/site-packages for pip and to /usr/local/lib/python3.x/site-packages for pip3.

  • To install a package from PyPI for only yourself:
$ pip install --user foobar

This installs the package files to ~/.local/lib/python2.x/site-packages.

  • To uninstall a package that was installed for all users:
$ sudo pip uninstall foobar
  • To uninstall a package that was installed only for you:
$ pip uninstall --user foobar
  • To upgrade an installed package:
$ pip install --upgrade foobar
  • To list all installed packages and their versions:
$ pip list
  • To search PyPI for a package by name:
$ pip search foobar
  • To list the installed file paths of a package:
$ pip show -f foobar