00:00 When you work with a virtual environment, and you only install the packages that you need for your project, you have a good chance of keeping the list of installed packages in your virtual environment tidy. Still, you may reach the point where you want to uninstall packages.
The command for uninstalling packages looks very similar to the
install command, but this time, instead of
install, you type
So for Windows, this is
python -m pip uninstall, and then the package name. For macOS and Linux, you would use the
If you can install a package with
pip, then it only makes sense that you can also uninstall a package. Let’s uninstall the
requests package now.
So here I am in my project folder. The virtual environment is not activated yet, so I activate it again with
activate, and I use
python3 -m pip list to show you what I have installed right now in my virtual environment.
To uninstall the
requests package, you type
python3 -m pip uninstall
pip actually removes anything from your computer, it asks for your permission first. Type
Y and press Enter to continue.
You should then see the following message confirming that
requests was removed:
Successfully uninstalled requests. Now take a look at your package list again with
python3 -m pip list.
requests, but it didn’t remove any of its dependencies. This behavior is a feature, not a bug. Imagine that you’ve installed several packages into your environment with
pip, some of which share dependencies.
pip uninstalled a package and its dependencies, then it would render any other packages requiring those dependencies unusable. So for now though, go ahead and remove the remaining packages by running
pip uninstall on them.
You can uninstall all four in a single command,
-m pip uninstall, and then
idna urllib3, all divided by a space, and then press Enter When you’re done, verify that everything has been removed by running
pip list again:
python3 -m pip list.
You now see the same list of packages you saw when you first started. It’s only
setuptools left in your virtual environment.
That means you successfully uninstalled all the packages that you installed with
pip. By the way, instead of uninstalling some or all installed packages of a virtual environment, you can also just delete the
venv folder, re-create a new virtual environment, and then install any packages that you need.
Often that’s faster than running multiple
pip uninstall commands. There is also quite convenient way of installing multiple packages at once. I’ll tell you more about it in the next lesson.
Become a Member to join the conversation.