Python setuptools 的依赖项自动发现? [英] Dependencies auto discovery for Python setuptools?

查看:94
本文介绍了Python setuptools 的依赖项自动发现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 setuptools 打包 Python 应用程序时,我将使用我的应用程序的所有 PyPI 依赖项填充 install_requires 列表.我发现自己手动梳理了所有来源以找到这些.这是正确的方法吗?或者这个列表可以以某种方式自动填充吗?

In packaging a Python application using setuptools, I am populating the install_requires list with all the PyPI dependencies of my application. I find myself manually combing through all my sources to find these. Is this the right way to do it? Or can this list be auto-populated somehow?

推荐答案

在我看来 install_requires 应该只列出项目的直接依赖项(而不是间接的那些,您的依赖项的依赖项).所以它通常是一个相对较短的列表,可能应该手工策划,就像你仔细挑选你的图书馆一样.

From my point of view install_requires should only list the direct dependencies of your project (not the indirect ones, the dependencies of your dependencies). So it often is a relatively short list, that can probably should be curated by hand, the same way you carefully hand-picked your libraries to begin with.

在常见情况下,使用 toxlinting 工具,例如 pylint 会让你知道某些导入是否无法解析,这很可能意味着install_requires中缺少库.

In common scenarios, using tox in combination with a linting tool such as pylint would let you know if some imports can't be resolved, which most likely means that libraries are missing from install_requires.

如果您已经有很多依赖项但忘记了哪些依赖项并且没有使 install_requires 保持最新,那么我相信诸如 pipreqspigar 可以提供帮助(可能还有其他类似的工具,但这是我在浏览以下类似问题时偶然发现的那些:12).

In the case you already have lots of dependencies but lost track of which ones and didn't keep install_requires up to date, then I believe a tool such as pipreqs or pigar can help (there are probably other similar tools, but that's the ones I stumbled upon while browsing the following similar questions: 1, 2).

这篇关于Python setuptools 的依赖项自动发现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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