Python setuptools 的 pkg_resources 模块是否支持 pip 的所有功能?

huangapple go评论54阅读模式
英文:

Does Python setuptools pkg_resources module support everything pip does?

问题

Python的包管理器(pip)支持几个操作符来指定版本:==~=>=<=

在我的程序中,我正在使用setuptoolspkg_resources来检查所需模块的正确版本是否已安装:

import pkg_resources
pkg_resources.require(requests~=2.28.2)

pkg_resources是否以与pip完全相同的方式处理==~=>=<=操作符?如果不是,是否有替代方法?

英文:

Python's package manager (pip) supports several operators for specifying version: ==, ~=, &gt;=, and &lt;=.

In my program, I am using setuptools' pkg_resources library to check that the correct versions of the required modules are installed:

import pkg_resources
pkg_resources.require(requests~=2.28.2)

Does pkg_resources handle the ==, ~=, &gt;=, and &lt;= operators the exact same way pip does? If not, is there an alternative that does?

答案1

得分: 1

pip 在内部使用 packaging 处理 版本规范,因此我建议您在可能的情况下也使用这个库。

setuptoolspkg_resources 被标记为废弃,因此我不建议您使用,除非您确信这是您想要做的,并理解后果。

我不确定是否有其他库提供与 pkg_resources.require() 相同的功能,因此您可能被困在这一点。

英文:

pip uses the packaging library internally to handle version specifiers, so I recommend you use this library as well whenever possible.

setuptools' pkg_resources is marked as deprecated, so I do not recommend you use it unless you are really confident this is what you want to do and understand the consequences.

I am not sure there is any other library that offers the same feature as pkg_resources.require(), so you might be stuck with this.

huangapple
  • 本文由 发表于 2023年4月17日 07:55:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76030902.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定