Python:如何检测未使用的包并删除它们 [英] Python: How to detect unused packages and remove them

查看:531
本文介绍了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.

这篇关于Python:如何检测未使用的包并删除它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆