Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Uninstalling Packages

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.

00:15 The command for uninstalling packages looks very similar to the pip install command, but this time, instead of install, you type uninstall.

00:25 So for Windows, this is python -m pip uninstall, and then the package name. For macOS and Linux, you would use the python3 command.

00:37 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.

00:46 So here I am in my project folder. The virtual environment is not activated yet, so I activate it again with source venv/bin/ activate, and I use python3 -m pip list to show you what I have installed right now in my virtual environment.

01:07 To uninstall the requests package, you type python3 -m pip uninstall requests.

01:18 Before pip actually removes anything from your computer, it asks for your permission first. Type Y and press Enter to continue.

01:28 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.

01:41 Notice that pip uninstalled 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.

01:57 If 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.

02:12 You can uninstall all four in a single command, python3 -m pip uninstall, and then certifi charset-normalizer

02:25 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.

02:43 You now see the same list of packages you saw when you first started. It’s only pip and setuptools left in your virtual environment.

02:51 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.

03:14 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.