Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to delete an installed module in Python?
Python provides several methods to uninstall installed packages. The most common approaches are using pip (Python's default package manager) or conda (for Anaconda/Miniconda environments).
Uninstalling a Package Using pip
The pip command is Python's standard package manager. It allows you to install, upgrade, and uninstall Python packages from the Python Package Index (PyPI).
Basic Syntax
pip uninstall package_name
Example: Uninstalling scipy
Here's how to uninstall the scipy package using pip ?
pip uninstall scipy
The output will show the files to be removed and ask for confirmation ?
Found existing installation: scipy 1.8.1 Uninstalling scipy-1.8.1: Would remove: c:\users\lenovo\appdata\local\programs\python\python310\lib\site-packages\scipy-1.8.1.dist-info\* c:\users\lenovo\appdata\local\programs\python\python310\lib\site-packages\scipy\* Proceed (Y/n)? y Successfully uninstalled scipy-1.8.1
Additional pip Options
You can use additional flags with pip uninstall ?
# Skip confirmation prompt pip uninstall -y package_name # Uninstall for specific Python version pip3 uninstall package_name # Uninstall user-installed package pip uninstall --user package_name
Limitations of pip uninstall
Note: pip cannot remove the following types of packages ?
Pure distutils packages installed with
python setup.py install(no metadata stored)Development installations created with
python setup.py developSystem packages installed by the operating system
For such packages, you can create a record during installation and manually remove files ?
python setup.py install --record files.txt
Uninstalling a Package Using conda
If you're using Anaconda or Miniconda, conda is the preferred package manager. It handles both Python packages and system dependencies.
Basic Syntax
conda uninstall package_name
Example: Uninstalling numpy
Here's how to uninstall numpy using conda ?
conda uninstall numpy
The output shows the package plan and dependencies to be removed ?
Collecting package metadata (repodata.json): done
Solving environment: done
## Package Plan ##
environment location: C:\Users\Lenovo\anaconda3
removed specs:
- numpy
The following packages will be REMOVED:
blas-1.0-mkl
intel-openmp-2021.4.0-haa95532_3556
mkl-2021.4.0-haa95532_640
mkl-service-2.4.0-py39h2bbff1b_0
mkl_fft-1.3.1-py39h277e83a_0
mkl_random-1.2.2-py39hf11a4ad_0
numpy-1.23.1-py39h7a0a035_0
numpy-base-1.23.1-py39hca35cd5_0
Proceed ([y]/n)? y
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
Additional conda Options
# Uninstall from specific environment conda uninstall -n myenv package_name # Skip confirmation conda uninstall --yes package_name # Remove all unused dependencies conda uninstall --prune package_name
Comparison
| Method | Best For | Handles Dependencies |
|---|---|---|
pip uninstall |
Standard Python packages | Limited |
conda uninstall |
Anaconda environments | Yes (automatically) |
Conclusion
Use pip uninstall for standard Python packages and conda uninstall for Anaconda environments. conda provides better dependency management by automatically removing unused dependencies along with the target package.
