Python: How to detect unused packages and remove them

user2492364 picture user2492364 · Apr 12, 2016 · Viewed 12.8k times · Source

I use pip freeze > requirements.txt to gather all packages I installed. But after developing many days, some packages are now unused. How can I find these unused packages and remove them, to make my project more clear?

Answer

MrSoloDolo picture MrSoloDolo · Jun 15, 2020

Inside Pycharm Go to code > inspect code Select Whole project option and click OK.

In inspection results panel locate Package requirements section under Python (note that this section will be showed only if there is any requirements.txt or setup.py file). The section will contain one of the following messages:

  • Package requirement '' is not satisfied if there is any package that is listed in requirements.txt but not used in any .py file.

  • Package '' is not listed in project requirements if there is any package that is used in .py files, but not listed in requirements.txt.

You have all your required packages remove/add them accordingly.