There are a variety of utilities available to work with Python packages. Every so often, a developer needs to uninstall Python packages from a system. Uninstalling packages is as easy as installing them.
As it is easy to install packages and forget what has been installed in the past, pip
provides the ability to list all currently installed packages, as well as indicating which ones are out of date. The examples in the next section are from the Python list (https://pip.pypa.io/en/stable/reference/pip_list/) and show documentation pages (https://pip.pypa.io/en/stable/reference/pip_show/).
Finally, when looking for packages to install, rather than opening a browser and navigating to PyPI directly, it is possible to find packages from the command line.
- To uninstall packages, run the
pip uninstall <package_name>
command. This will uninstall most packages on the system. - Requirements files can be used to remove a number of packages at once, by using the
-r
option, such aspip uninstall -r <requirements_file>
. The-y
option allows for automatic confirmation of file removal.
- List currently installed packages by running
pip list
.
- To show packages that are outdated, use
pip list --outdated
, as follows:
$ pip list --outdated
docutils (Current: 0.10 Latest: 0.11)
Sphinx (Current: 1.2.1 Latest: 1.2.2)
While it is possible to update all outdated packages at once, this is not available within pip
itself. There are two primary options: the first involves using sed
, awk
, or grep
to walk through the list of packages, find the outdated packages, and update them. Alternatively, install the package pip-review
to see outdated packages and update them. In addition, a number of other tools have been created by different developers, as well as instructions on how to do it yourself, so you should decide which works best for you.
Note
Note: Automatically upgrading all Python packages can break dependencies. You should only update packages on an as-needed basis.
$ pip show sphinx
Name: Sphinx
Version: 1.7.2
Summary: Python documentation generator
Home-page: http://sphinx-doc.org/
Author: Georg Brandl
Author-email: [email protected]
License: BSD
Location: /my/env/lib/python2.7/site-packages
Requires: docutils, snowballstemmer, alabaster, Pygments,
imagesize, Jinja2, babel, six
- Run the command
pip search "query_string"
. The example below comes from https://pip.pypa.io/en/stable/reference/pip_search/, and shows how the output looks:
$ pip search peppercorn
pepperedform - Helpers for using peppercorn with formprocess.
peppercorn - A library for converting a token stream into [...]
When searching for packages, the query can be a package name or simply a word, as pip
will find all packages with that string in the package name or in the package description. This is a useful way to locate a package if you know what you want to do but don't know the actual name of the package.
Packages installed with python setup.py install
, and program wrappers that were installed using python setup.py develop
, cannot be uninstalled via pip
, as they do not provide metadata about which files were installed.
A number of other options are available for listing files, such as listing only non-global packages, beta versions of packages, outputting the list in columns, and other tools that may prove useful.
Additional information can be shown by using the --verbose
option, as shown in the following screenshot:
The verbose option shows the same information as the default mode, but also includes such information as the classifier information that would found on the package's PyPI page. While this information could obviously be found simply by going to the PyPI site, if you are on a stand-alone computer or otherwise unable to connect to the internet, this can be useful when figuring out whether a package is supported by our current environment or when looking for similar packages within a particular topic.