Python: How to detect unused packages and remove them
Solution 1
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.
Solution 2
I just found this: https://pypi.python.org/pypi/pip_check_reqs/2.0.
Find packages that should or should not be in requirements for a project
Related videos on Youtube

user2492364
Updated on August 07, 2020Comments
-
user2492364 over 2 years
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?-
Matt C over 6 years
-
A Jar of Clay over 2 yearsDoes this answer your question? Delete unused packages from requirements file
-
-
Khushhal over 2 yearsIt gives error: ModuleNotFoundError: No module named 'pip._internal.download' It doesn't work in June 2020 because PYPA have changed how pip behaves so few pip APIs are not available for direct use, making this library completely useless.
-
Janaka Peiris about 1 year@Khushhalm Use the latest version 2.3.0 to get rid of this error. But still I'm not sure of its pip-extra-reqs output, as it listed almost all packages