Python:如何检测未使用的包并删除它们
我使用 pip freeze >requirements.txt
收集我安装的所有软件包.但是开发多天了,有些包现在没用了.如何找到这些未使用的包并删除它们,使我的项目更清晰?
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?
Pycharm 内部转到代码>检查代码选择整个项目选项并点击确定.
Inside Pycharm Go to code > inspect code Select Whole project option and click OK.
在检查结果面板中找到 Python 下的 Package requirements 部分(注意,只有在有任何 requirements.txt 或 setup.py 文件时才会显示此部分).该部分将包含以下消息之一:
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:
如果有任何在 requirements.txt 中列出但未在任何 .py 文件中使用的包,则不满足包要求".
Package requirement '' is not satisfied if there is any package that is listed in requirements.txt but not used in any .py file.
如果有任何包在 .py 文件中使用但未在 requirements.txt 中列出,则包 '' 未列在项目要求中.
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.