How to Uninstall Python Packages

How to Uninstall Python Packages

The Pip and Pipenv Package Managers can be used to uninstall Python packages.

Checklist

Before packages can be uninstalled, ensure that a Python installation containing the necessary files needed for uninstalling packages is in place. Installation Requirements.

How to Uninstall Packages Installed with Pip

To uninstall a package: 

pip uninstall <packagename>

How to Uninstall Packages in a Python Virtual Environment

Packages can be uninstalled from a virtual environment using pip or pipenv. 

To use pip to uninstall a package locally in a virtual environment:

  1. Open a command or terminal window (depending on the operating system) 
  2. cd into the project directory
  3. pip uninstall <packagename>

To use pipenv to uninstall a package locally in a virtual environment created with venv or virtualenv:

  1. Open a command or terminal window (depending on the operating system) 
  2. cd into the project directory
  3. pipenv uninstall <packagename>

How to Globally Uninstall Python Packages

In some cases, packages may be installed both locally (e.g., for use in a specific project) and system-wide. To ensure a package is completely removed from your system after you’ve uninstalled it locally, you’ll also need to uninstall it globally.

To uninstall a package globally in Windows: 

    1. Open a command window by entering ‘cmd’ in the Search Box of the Task bar
    2. Press Ctrl+Shift+Enter to gain Administration (Admin) privileges
    3. pip uninstall <packagename>

To uninstall a package globally in Linux:

    1. Open a terminal window
    2. sudo su pip uninstall <packagename>

How to Uninstall Package Dependencies with Pip

When you install a package with pip, it also installs all of the dependencies the package requires. Unfortunately, pip does not uninstall dependencies when you uninstall the original package. Here are a couple of different procedures that can be used to uninstall dependencies.

  1. If a package has been installed via a pip requirements file (i.e., pip install requirements.txt), all of the packages in requirements.txt can be uninstalled with the following command:
pip uninstall requirements.txt
  1. If a requirements.txt file is not available, you can use the pip show command to output all the requirements of a specified package:
pip show <packagename>

Example:

pip show cryptography

Output should be similar to: 

'Requires: six, cffi'

These dependencies can then be uninstalled with the pip uninstall command. However before uninstalling, you should ensure that the packages are NOT dependencies for other existing packages.

How to Uninstall Package Dependencies with Pipenv

To uninstall all the dependencies in a Pipenv project: 

  1. Open a command or terminal window
  2. cd into the project directory
  3. pipenv uninstall --all

How to Uninstall a Package Installed With Setuptools

Any packages that have been configured and installed with setuptools used the following command: 

python setup.py install 

Unfortunately, there is no python setup.py uninstall command. To uninstall a package installed with setup.py, use the pip command:

pip uninstall <packagename>

Be aware that there are a few exceptions that cannot be uninstalled with pip, including:

  • Distutils packages, which do not provide metadata indicating which files were installed.
  • Script wrappers installed by the setup.py develop command.

Next Steps

  • Create a custom Python runtime for your next project. Pick just the packages you need, and we’ll automatically resolve all dependencies, build it (including C code) and package it for your platform.

How to Uninstall Python Packages with the ActiveState Platform

Try a faster way of installing Python packages for Windows. Get ActivePython or build your own Python runtime with the packages you need. Get started free on the ActiveState Platform.

Related Quick Reads:

How to Update All Python Packages

Python Packages

Mike