pypa / pip

The Python package installer
https://pip.pypa.io/
MIT License
9.51k stars 3.02k forks source link

Add option to uninstall packages not in requirements file #716

Open wodow opened 11 years ago

wodow commented 11 years ago

Currently a requirements file is used to specify what packages should be installed (and how, in some cases).

I believe it would be useful to have an additional option to uninstall all packages that do not appear in a supplied requirements file.

This would be useful for tightly controlling installing to a virtualenv or indeed any situation where you want to be absolutely confident that you have only the packages you desire.

Discussion on Stack Overflow: http://stackoverflow.com/questions/13176968/how-can-i-use-a-pip-requirements-file-to-uninstall-as-well-as-install-packages/

Regressor commented 3 years ago

Recently I have a case: We have a large legacy project and replaced django-rest-auth/djangorestframework-jwt packets (and their dependency PyJWT-1.7.1) with dj-rest-auth/djangorestframework-simplejwt packets. Stage/prod docker images are built from scratch and there is no problem, but developers envs have old packets installed and pip install -r requirements.txt fails to finish because of PyJWT-1.7.1/2.1.0 conflict. To get it back they have to remove packages by hand or recreate env. And there is a pain switching branches.

Why there is no future to add some packages to requirement.txt as uninstall_if_exists ?

pradyunsg commented 3 years ago

Because this functionality exists in the pip-sync command, that’s developed externally to pip.

uranusjr commented 2 years ago

Do we still want to work on this if pip sync is available? See #10636