Uninstalling Packages Using pip
Occasionally, you’ll want to uninstall a package. The safest way to do this is by running pip show
on every package you have installed, ensuring that the package you want to uninstall does not show up in the requires:
line for any package.
Once you’re confident you can uninstall a package, you can do so with pip uninstall
. Later, if you discover that you’ve accidentally removed a dependency of another package, you can reinstall that package, and pip
will automatically redownload the missing dependency.
00:00 Occasionally, you’ll want to remove a package in your environment. Maybe you found a better package that does the same thing, or you just don’t recognize a package as a dependency and you want to remove it.
00:14
The safest way to do this is to run the show
command on every package installed to ensure that it doesn’t depend on the package you want to uninstall.
00:25
This is important because pip
will not warn you of any other packages that depend on the one you’re trying to uninstall, so this process must be done manually.
00:37
People have created tools to automate this process, but I’m not using them here to enforce the fact that it’s good to understand your dependency tree, particularly in small-to-medium sized applications, where that’s very doable. Once you’re confident you can uninstall a package, you can run pip uninstall
and then the name of the package. Press y
to confirm. You can also append -y
to the uninstall
command to suppress this confirmation prompt, just like this. Later on, if you discover that you accidentally deleted a dependency to another package, you can always re-install the broken package and it will automatically re-download just the missing dependency.
Bartosz Zaczyński RP Team on Aug. 7, 2020
I believe that’s because there’s no single way of specifying dependencies in Python. In some cases, they can’t be determined until you run the code.
Become a Member to join the conversation.
Thomas Piekarski on Aug. 7, 2020
Is there any reason why pip is not offering to check if packages are used by any other packages before uninstalling?