We will show you how to uninstall a pip package that you installed with
pip install. pip is a package management tool which can be used to install and manage software packages written in Python, which can be found in the Python Package Index (PyPI). pip is a recursive acronym that can stand for either “Pip Installs Packages” or “Pip Installs Python”. Alternatively, pip stands for “preferred installer program”. Let’s see how you can use pip to remove packages.
If you followed one of our previous tutorials about how to install and use pip on Ubuntu 16.04 or how to install and use pip on CentOS 7 and you installed some Python packages that you don’t want to use anymore, you can easily uninstall them using pip.
1. Pip List Installed
First of all, connect to your Linux server via SSH. Then list the currently installed packages using the following command:
# pip list authorize (0.1.0) backports.ssl-match-hostname (22.214.171.124) beautifulsoup4 (4.6.0) bs4 (0.0.1) chardet (3.0.4) decorator (3.4.0) ...
2. Pip Uninstall
All these packages are currently installed via pip and you can uninstall any package that you don’t need. To uninstall a package installed with
pip install you can use
pip uninstall. For example, to uninstall the
beautifulsoup4 package you can use the following command:
pip uninstall beautifulsoup4
Once you run the command, pip will ask you to confirm the action. Answer with
y to confirm and the package will be uninstalled from the system.
# pip uninstall beautifulsoup4 Uninstalling beautifulsoup4-4.6.0: ... Proceed (y/n)? y Successfully uninstalled beautifulsoup4-4.6.0
As you can see, uninstalling packages with pip is as simple as installing them. Learning how you can manage the packages installed on your server with pip will help you to build better applications. pip is also useful for many other tasks, like updating a package which is currently installed, or installing a specific version of the package you need for the project. For a full list of options you can use with pip, you can use
[root@vps /]# pip --help Usage: pip [options] Commands: install Install packages. download Download packages. uninstall Uninstall packages. freeze Output installed packages in requirements format. list List installed packages. show Show information about installed packages. check Verify installed packages have compatible dependencies. search Search PyPI for packages. wheel Build wheels from your requirements. hash Compute hashes of package archives. completion A helper command used for command completion. help Show help for commands. General Options: -h, --help Show help. --isolated Run pip in an isolated mode, ignoring environment variables and user configuration. -v, --verbose Give more output. Option is additive, and can be used up to 3 times. -V, --version Show version and exit. -q, --quiet Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR, and CRITICAL logging levels). --log <path> Path to a verbose appending log. --proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port. --retries <retries> Maximum number of retries each connection should attempt (default 5 times). --timeout <sec> Set the socket timeout (default 15 seconds). --exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort. --trusted-host <hostname> Mark this host as trusted, even though it does not have valid or any HTTPS. --cert <path> Path to alternate CA bundle. --client-cert <path> Path to SSL client certificate, a single file containing the private key and the certificate in PEM format. --cache-dir <dir> Store the cache data in <dir>. --no-cache-dir Disable the cache. --disable-pip-version-check periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index.
The easiest way to remove all packages installed by pip is by executing the following command:
pip uninstall -y -r <(pip freeze)
4. Create a Bash Alias
We suggest you create a bash alias with his command:
alias pipuninstallall="pip uninstall -y -r <(pip freeze)"
Then all you have to do is just run
5. Alternative Solution for pipenv
If you are using pipenv you can just run:
pipenv uninstall --all
For more information on how to use the pip uninstall, you can refer to the pip documentation for pip uninstall and more usage examples.
Of course, you don’t have to use pip uninstall to remove installed packages, if you use one of our Managed Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to uninstall with pip. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post, on how to use pip uninstall, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.