LinuxCommandLibrary

pip-uninstall

Uninstall Python packages

TLDR

Uninstall a package

$ pip uninstall [package]
copy

Uninstall packages listed in a specific file
$ pip uninstall [[-r|--requirement]] [path/to/requirements.txt]
copy

Uninstall package without asking for confirmation
$ pip uninstall [[-y|--yes]] [package]
copy

SYNOPSIS

pip uninstall [options] <package>...
pip uninstall [options] -r <requirements_file>

PARAMETERS

-y, --yes
    Don't ask for confirmation of uninstall deletions. Removes packages without prompting.

-r, --requirements <file>
    Uninstall all the packages listed in the specified requirements file.

-e, --editable <path/url>
    Uninstall an editable project (e.g., one installed with pip install -e .) by specifying its path or URL.

-t, --target <dir>
    Target directory from which to uninstall packages, instead of the default installation location.

--dry-run
    Perform a dry run: show what would be uninstalled without actually performing any deletions.

-h, --help
    Show the command's help message and exit.

-v, --verbose
    Increase output verbosity. Can be used multiple times for more detail.

-q, --quiet
    Suppress output. Can be used multiple times for less detail.

--no-input
    Do not prompt for any input, including confirmation prompts.

--break-system-packages
    (DANGEROUS) Allow pip to modify system-wide packages. Use with extreme caution as it can destabilize your system's Python environment.

DESCRIPTION

pip uninstall is a command-line utility provided by pip, the Python package installer, used to remove installed Python packages from your system or a specific Python environment.

When executed, it identifies the files associated with the specified package(s) and prompts the user for confirmation before deleting them. This includes package code, metadata, and scripts installed by the package. It helps maintain a clean and organized Python environment, allowing developers to remove unused dependencies or resolve conflicts caused by different package versions.

Unlike some system package managers, pip uninstall does not automatically uninstall packages that were installed as dependencies of the package being removed, nor does it resolve reverse dependencies (i.e., it won't tell you if other installed packages depend on the one you're removing). Users must manually manage these relationships, which can sometimes lead to broken environments if not handled carefully.

It is highly recommended to use pip uninstall within isolated Python environments (like virtual environments) to prevent unintended removal of packages that might be crucial for system-wide applications or other projects.

CAVEATS

Dependency Management: pip uninstall does not automatically uninstall unused dependencies or check for reverse dependencies. Manually track dependencies to avoid breaking other installed packages.

System-Wide Installations: Avoid uninstalling packages from your system's global Python environment directly. Always prefer using virtual environments to isolate project dependencies and prevent conflicts.

Permissions: You need appropriate write permissions to the installation directories (e.g., site-packages) to uninstall packages. Using sudo with pip is generally discouraged unless strictly necessary and understood.

Incomplete Uninstalls: In rare cases, especially with manually installed packages or unusual package structures, pip uninstall might not remove all associated files. Manual cleanup may be required.

BEST PRACTICES FOR UNINSTALLING

Always use pip uninstall within a virtual environment to ensure that only project-specific dependencies are affected. Before uninstalling a critical package, consider using the --dry-run option to see exactly what files will be removed. Regularly review your project's requirements.txt to manage dependencies effectively.

RESOLVING DEPENDENCY ISSUES

Since pip uninstall doesn't manage reverse dependencies, if you encounter 'ModuleNotFoundError' after uninstalling a package, it's likely another package relied on it. Use pip show <package_name> to see its dependencies, and consider reinstalling the necessary package or finding an alternative.

HISTORY

The pip package manager emerged as an improvement over easy_install and was officially adopted as the recommended tool for installing Python packages. The uninstall functionality has been a core component of pip from its early development, providing essential package management capabilities. Its design reflects a philosophy of explicit control over installed packages rather than automatic dependency resolution for removal, contrasting with some system package managers.

SEE ALSO

pip install(1), pip list(1), pip show(1), pip freeze(1), python -m venv(1)

Copied to clipboard