A Guide to Managing Python Packages with Command Line Utilities

In this blog post, we will learn about various command line utilities that help you manage Python packages in your Python environment. As Python developers, we need to understand how we manage Python packages in a Python environment so that we can triage failures when we use Python packages and upgrade or downgrade these packages as needed.

Prerequisites

To learn about different command line utilities to manage Python packages you would the following setup and command line tools:-

  1. A Python environment

  2. Any Python package that you would want to install/remove/upgrade in the environment (I will use data-understand in this article)

  3. pip (You can install pip using the command python -m pip install --upgrade pip)

Installing a new Python package

You could install a new Python package using pip install <python-package-name>. This usually installs the most recent version of the Python package on pypi. For example, to install data-understand you can execute the following command:-

pip install data-understand

Installing a specific version of the Python package

If you want to install a specific version of a Python package, then you can specify the version number in the pip install command as pip install <python-package-name>==<version>. You can look up the version of the Python package that you want to install on pypi. For example, to install data-understand at version 0.0.5 you can execute the following command:-

pip install data-understand==0.0.5

You can also use this command to downgrade or upgrade a Python package.

Checking the version of the Python package

You can use pip show <python-package> to see what is the current version of your python package installed in your local python environment. For example to see what is the current version of data-understand you can execute the following:-

pip show data-understand

Upgrading an existing Python package

If you find that you don't have the most recent version of your Python package installed locally, you can upgrade it to the most recent version using the command pip install --upgrade <python-package>. For example, to update an existing version of data-understand to the latest available on pypi, you could do the following:-

pip install --upgrade data-understand

Removing a Python package

You could remove a Python package from your Python environment using the command pip uninstall <python-package>. To remove data-understand from the Python environment you could execute the following command:-

pip uninstall data-understand