How to List Installed Packages and Version using pip tool

Posted on

Introduction

This is a specific article to show how to achieve the purpose in the title description. It is about how to list installed packages along with each of its version. It is simple to perform with just a tool with the name of ‘pip’. Basically, pip is a tool for installing and managing packages in python. The information about pip tool is available using the command ‘whatis’ as follows :

user@hostname:~$ whatis pip
pip (1)              - A tool for installing and managing Python packages
user@hostname:~$ 

The tool is available for managing and installing packages specifically in a python virtual environment. In order to use the ‘pip’ tool, there is a specific requirement for it. There must be a package with part of the name containing ‘python-pip’. Just search it first to make sure about the complete name with the following comthonmand :

apt search python-pip

The following is the output of the above command if there is a package with part of the name using ‘python-pip’ :

root@hostname ~# apt search python-pip
Sorting... Done
Full Text Search... Done
python-pip/bionic-updates 9.0.1-2.3~ubuntu1.18.04.1 all
  Python package installer

python-pip-whl/bionic-updates,now 9.0.1-2.3~ubuntu1.18.04.1 all [installed,automatic]
  Python package installer

root@hostname ~# 

As in the above output command, there are two packages. Each of them are python-pip and also python-pip-whl. In the context of this article, it is a coincidence that there is already a ‘python-pip’ package available. The following is the command to check whether it is already installed or not :

root@hostname ~# apt list --installed | grep pip

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

libpipeline1/bionic,now 1.5.0-1 amd64 [installed,automatic]
python-pip-whl/bionic-updates,now 9.0.1-2.3~ubuntu1.18.04.1 all [installed,automatic]
root@hostname ~#

Apparently, there is an installed package with the name of ‘python-pip-whl’. So, in order to find out the usage of that package, just execute the following command :

root@hostname ~# dpkg -s python-pip-whl
Package: python-pip-whl
Status: install ok installed
Priority: optional
Section: python
Installed-Size: 1813
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: all
Source: python-pip
Version: 9.0.1-2.3~ubuntu1.18.04.1
Replaces: python-chardet-whl (<< 2.3.0-2), python-colorama-whl (<< 0.3.6-1), python-distlib-whl (<< 0.2.2-1), python-html5lib-whl (<< 0.999-4), python-requests-whl (<< 2.9.1-3), python-setuptools-whl (<< 20.1.1-1), python-six-whl (<< 1.10.0-3), python-urllib3-whl (<< 1.13.1-2), virtualenv (<< 14.0.5+ds-5)
Depends: ca-certificates
Breaks: python-chardet-whl (<< 2.3.0-2), python-colorama-whl (<< 0.3.6-1), python-distlib-whl (<< 0.2.2-1), python-html5lib-whl (<< 0.999-4), python-requests-whl (<< 2.9.1-3), python-setuptools-whl (<< 20.1.1-1), python-six-whl (<< 1.10.0-3), python-urllib3-whl (<< 1.13.1-2), virtualenv (<< 14.0.5+ds-5)
Description: Python package installer
 pip is the Python package installer.  It integrates with virtualenv, doesn't
 do partial installs, can save package state for replaying, can install from
 non-egg sources, and can install from version control repositories.
 .
 This is the support package for the PEP 427 wheel version of the package,
 required for using pip inside a virtual environment.
Built-Using: appdirs (= 1.4.0-2), chardet (= 2.3.0-2), distlib (= 0.2.4-1), html5lib (= 0.999999999-1), pyparsing (= 2.1.10+dfsg1-1), python-cachecontrol (= 0.11.7-1), python-colorama (= 0.3.7-1), python-distro (= 1.0.1-1), python-ipaddress (= 1.0.17-1), python-lockfile (= 1:0.12.2-2), python-packaging (= 16.7-2), python-progress (= 1.2-1), python-retrying (= 1.3.3-1), python-setuptools (= 32.3.1-1), python-urllib3 (= 1.16-1), python-webencodings (= 0.5-1), requests (= 2.11.1-1), six (= 1.10.0-3)
Homepage: https://pip.pypa.io/en/stable/
Original-Maintainer: Debian Python Modules Team <python-modules-team@lists.alioth.debian.org>
root@hostname ~# 

The main information about the usage of that package is available in the line
This is the support package for the PEP 427 wheel version of the package,
required for using pip inside a virtual environment.

 

 

Listing Installed Packages using ‘pip’ tool

Finally, how can pip list the installed package with each of their version ?. Just execute the ‘pip’ command with an additional parameter :

(python-env) root@hostname:~ $ pip list
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Package    Version
---------- -------
pip        19.1.1 
setuptools 41.0.1 
wheel      0.33.4 
(python-env) root@hostname:~ $

Don’t forget to create and activate the python virtual environment. Read the article in this link with the title of ‘How to Create a Python Virtual Environment’ and also with the title of ‘How to Create a Python 3.6 Virtual Environment’ in this link for creating the python virtual environment. Furthermore, read the article in this link to activate the python virtual environment with the title of ‘How to Activate Python Virtual Environment’.

Leave a Reply