- How to Uninstall Python Packages
- Checklist
- How to Uninstall Packages Installed with Pip
- How to Uninstall Packages in a Python Virtual Environment
- How to Globally Uninstall Python Packages
- How to Uninstall Package Dependencies with Pip
- How to Uninstall Package Dependencies with Pipenv
- How to Uninstall a Package Installed With Setuptools
- Next Steps
- Installing and removing packages¶
- Uninstalling¶
How to Uninstall Python Packages
All Python package management solutions provide the basic function of uninstalling packages, including pip, pipenv and the ActiveState Platform. However, unless specifically defined in a requirements.txt or pipfile.lock, package managers will not deal with transitive dependencies (ie., dependencies of dependencies).
In this article, we explain how to uninstall Python packages using these popular tools and we also introduce you to the ActiveState Platform. The AS Platform is unique in automatically installing and uninstalling transitive dependencies. Our dependency management system makes it possible to track conflicts between packages, know about platform-specific dependencies, and even track system-level dependencies like C and C++ libraries. Once you are done reading, you can try the ActiveState Platform by signing up for a free account .
Read on to understand how to work with Pip and Pipenv Package Managers 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 (for Windows).
How to Uninstall Packages Installed with Pip
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:
- Open a command or terminal window (depending on the operating system)
- cd into the project directory
- pip uninstall
To use pipenv to uninstall a package locally in a virtual environment created with venv or virtualenv:
- Open a command or terminal window (depending on the operating system)
- cd into the project directory
- pipenv uninstall
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:
-
- Open a command window by entering ‘cmd’ in the Search Box of the Task bar
- Press Ctrl+Shift+Enter to gain Administration (Admin) privileges
- pip uninstall
To uninstall a package globally in Linux:
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.
- 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
- If a requirements.txt file is not available, you can use the pip show command to output all the requirements of a specified package:
Output should be similar to:
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:
- Open a command or terminal window
- cd into the project directory
- 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:
Unfortunately, there is no python setup.py uninstall command. To uninstall a package installed with setup.py, use the pip command:
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
Resolving packages when installing or uninstalling an environment can be an extremely slow (or even manual) process. You can speed things up considerably using the ActiveState Platform, which automatically resolves dependencies for you–fast! Get started free on the ActiveState Platform.
Or just install Python 3.9 and use the included command line interface, the State Tool, to “state install” the packages you need:
>state install numpy ╔════════════════════╗ ║ Installing Package ║ ╚════════════════════╝ Updating Runtime ──────────────── Changes to your runtime may require some dependencies to be rebuilt. numpy includes 2 dependencies, for a combined total of 8 new dependencies. Building 8/8 Installing 8/8 Package added: numpy
Installing and removing packages¶
Changed in version 0.7: Allow paths as arguments as well.
Install a package in editable mode ( python setup.py develop ) from an online repository. Supported VCS are:
- Git (prefix git+ )
- Mercurial (prefix hg+ )
- Bazaar (prefix bzr+ )
- Subversion (prefix svn+ )
The URL syntax is as follows:
All fields are required. The last part ( #egg= ) specifies the package name.
You can run it with a path as well. Actually, this:
$ pyg install -e path/to/a/directory .
$ cd path/to/a/directory $ python setup.py develop
Do not install packages’ scripts.
Do not install packages’ data files.
Install packages from the specified requirement file:
$ pyg install -r requirements.txt
If the package is already installed, install it again. For example, if you have installed pypol_ v0.4 :
$ pyg install pypol_==0.4 Best match: pypol_==0.4 Downloading pypol_ Checking md5 sum Running setup.py egg_info for pypol_ Running setup.py install for pypol_ pypol_ installed successfully
Later you may want to re-install the package. Instead of running remove and then install, you can use the -U option:
$ pyg install -U pypol_ Best match: pypol_==0.5 Downloading pypol_ Checking md5 sum Installing pypol_ egg file pypol_ installed successfully
This command does not upgrade dependencies (see install -A).
Like, install —upgrade, but upgrade dependencies too.
Do not install package’s dependencies.
Specify the base URL of Python Package Index (default to http://pypi.python.org/pypi ).
The base installation directory for all packages.
Install the package in the user site-packages.
Uninstalling¶
Removing a package is dead simple:
Pyg tries to detect the package’s folder and delete it:
$ pyg remove sphinx Uninstalling sphinx /usr/bin/sphinx-build /usr/local/lib/python2.7/dist-packages/Sphinx-1.0.7-py2.7.egg /usr/bin/sphinx-quickstart /usr/bin/sphinx-autogen Proceed? (y/[n])
If packname is a module and not a package, Pyg will automatically detect it:
$ pyg remove roman Uninstalling roman /usr/local/lib/python2.7/dist-packages/roman.pyc /usr/local/lib/python2.7/dist-packages/roman.py Proceed? (y/[n])
If your answer is yes the files will be deleted. This operation is not undoable:
$ pyg remove itertools_recipes Uninstalling itertools_recipes /usr/local/lib/python2.7/dist-packages/itertools_recipes-0.1-py2.7.egg Proceed? (y/[n]) y Deleting: /usr/local/lib/python2.7/dist-packages/itertools_recipes-0.1-py2.7.egg. Removing egg path from easy_install.pth. itertools_recipes uninstalled succesfully
Do not ask confirmation of uninstall deletions:
$ pyg remove -y iterutils Uninstalling iterutils /usr/local/lib/python2.7/dist-packages/iterutils.py /usr/local/lib/python2.7/dist-packages/iterutils-0.1.6.egg-info /usr/local/lib/python2.7/dist-packages/iterutils.pyc Deleting: /usr/local/lib/python2.7/dist-packages/iterutils.py. Deleting: /usr/local/lib/python2.7/dist-packages/iterutils-0.1.6.egg-info. Deleting: /usr/local/lib/python2.7/dist-packages/iterutils.pyc. Removing egg path from easy_install.pth. iterutils uninstalled succesfully
Uninstall all the packages listed in the given requirement file.
$ echo -e 'itertools_recipes\niterutils' > reqfile.txt $ cat reqfile.txt itertools_recipes iterutils
$ pyg remove -r reqfile.txt Uninstalling itertools_recipes /usr/local/lib/python2.7/dist-packages/itertools_recipes.py /usr/local/lib/python2.7/dist-packages/itertools_recipes.pyc /usr/local/lib/python2.7/dist-packages/itertools_recipes-0.1.egg-info Proceed? (y/[n]) y Deleting: /usr/local/lib/python2.7/dist-packages/itertools_recipes.py. Deleting: /usr/local/lib/python2.7/dist-packages/itertools_recipes.pyc. Deleting: /usr/local/lib/python2.7/dist-packages/itertools_recipes-0.1.egg-info. Removing egg path from easy_install.pth. itertools_recipes uninstalled succesfully Uninstalling iterutils /usr/local/lib/python2.7/dist-packages/iterutils.py /usr/local/lib/python2.7/dist-packages/iterutils-0.1.6.egg-info /usr/local/lib/python2.7/dist-packages/iterutils.pyc Proceed? (y/[n]) y Deleting: /usr/local/lib/python2.7/dist-packages/iterutils.py. Deleting: /usr/local/lib/python2.7/dist-packages/iterutils-0.1.6.egg-info. Deleting: /usr/local/lib/python2.7/dist-packages/iterutils.pyc. Removing egg path from easy_install.pth. iterutils uninstalled succesfully
You can supply both packname (one or more) and requirement files:
$ pyg remove -r reqfile.txt docutils Uninstalling itertools_recipes /usr/local/lib/python2.7/dist-packages/itertools_recipes.py /usr/local/lib/python2.7/dist-packages/itertools_recipes.pyc /usr/local/lib/python2.7/dist-packages/itertools_recipes-0.1.egg-info Proceed? (y/[n]) y Deleting: /usr/local/lib/python2.7/dist-packages/itertools_recipes.py Deleting: /usr/local/lib/python2.7/dist-packages/itertools_recipes.pyc Deleting: /usr/local/lib/python2.7/dist-packages/itertools_recipes-0.1.egg-info Removing egg path from easy_install.pth. itertools_recipes uninstalled succesfully Uninstalling iterutils /usr/local/lib/python2.7/dist-packages/iterutils.py /usr/local/lib/python2.7/dist-packages/iterutils-0.1.6.egg-info /usr/local/lib/python2.7/dist-packages/iterutils.pyc Proceed? (y/[n]) y Deleting: /usr/local/lib/python2.7/dist-packages/iterutils.py Deleting: /usr/local/lib/python2.7/dist-packages/iterutils-0.1.6.egg-info Deleting: /usr/local/lib/python2.7/dist-packages/iterutils.pyc Removing egg path from easy_install.pth. iterutils uninstalled succesfully Uninstalling docutils /usr/local/lib/python2.7/dist-packages/docutils /usr/local/lib/python2.7/dist-packages/docutils-0.7.egg-info Proceed? (y/[n]) y Deleting: /usr/local/lib/python2.7/dist-packages/docutils Deleting: /usr/local/lib/python2.7/dist-packages/docutils-0.7.egg-info Removing egg path from easy_install.pth. docutils uninstalled succesfully
You can remove Pyg either with pyg remove pyg or pyg remove yourself .