Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uninstall unused packages with pip

I am updating all my packages with pip with

import pip
from subprocess import call

for dist in pip.get_installed_distributions():
    call("pip install --upgrade " + dist.project_name, shell=True)

but it takes forever since many more packages are installed than I actually need.

Can I delete all unused packages with pip?

like image 813
Jamgreen Avatar asked Dec 20 '25 08:12

Jamgreen


1 Answers

Of course you can delete any package you want. The real question is should you?

Is this in a virtualenv or is it system wide python? If it's system wide, just because your project isn't using those packages doesn't mean no other apps rely on them. If its a virtualenv, I would recommend creating a temp virtualenv, and installing only the packages that you know your project depends on. This way you can see which packages were installed as dependencies of packages you require and you can remove the ones that are not needed anymore.

like image 180
junnytony Avatar answered Dec 21 '25 21:12

junnytony



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!