Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tell which installed packages my Python project is not using? [duplicate]

Tags:

python

pycharm

I've been working on a project for a while now and have installed various packages over the time I've worked with it, some of which I suspect are no longer required to run the code, and I don't want to include them in the requirements.txt. Is there any way to know which installed packages in my venv are either imported somewhere in my Python project or are a dependency of a package that is imported, so that I can remove the unused packages from the requirements.txt?

  • My question is related to How can I 'clean up' a virtualenv? but is not the same, because in that case the OP knew which top-level package (of several he installed) he wanted to keep, and was trying to figure out how to uninstall the others along with their dependencies, while in my case I don't even know which top-level packages I need.
  • My question is similar to this one regarding the R programming language.
like image 525
Nathan Wailes Avatar asked Sep 06 '25 23:09

Nathan Wailes


1 Answers

I found a solution to my problem here: use pipreqs to get a list of the top-level packages actually required by a project:

pip install pipreqs and then pipreqs . (from the top level of your project).

like image 93
Nathan Wailes Avatar answered Sep 08 '25 12:09

Nathan Wailes