从需求文件中删除未使用的包 [英] Delete unused packages from requirements file

查看:19
本文介绍了从需求文件中删除未使用的包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么简单的方法可以从需求文件中删除不再使用的包?

Is there any easy way to delete no-more-using packages from requirements file?

我为此任务编写了一个 bash 脚本,但是它没有按我预期的那样工作.因为,有些包没有跟在它们的 PyPI 项目名称之后使用.例如;

I wrote a bash script for this task but, it doesn't work as I expected. Because, some packages are not used following their PyPI project names. For example;

dj-database-url

包用作

dj_database_url

我的项目在它自己的需求文件中有很多包,所以,一个一个地搜索它们太混乱、容易出错并且花费太多时间.正如我所搜索的,IDE 还没有这个属性.

My project has many packages in its own requirements file, so, searching them one-by-one is too messy, error-prone and takes too much time. As I searched, IDEs don't have this property, yet.

推荐答案

您可以在 PyCharm.

  1. 删除requirements.txt 的内容,但保留空文件.
  2. 加载您的项目,
  3. PyCharm 转到 Code ->检查代码....
  4. 在对话框中选择Whole project选项并点击OK.在检查结果面板中,找到 Python 下的 Package requirements 部分(注意只有当有任何 requirements.txt 时才会显示此部分>setup.py 文件).该部分将包含以下消息之一:
  1. Delete the contents of your requirements.txt but keep the empty file.
  2. Load your project in,
  3. PyCharm go to Code -> Inspect code....
  4. Choose Whole project option in dialog 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:

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