英文:
Does Python setuptools pkg_resources module support everything pip does?
问题
Python的包管理器(pip)支持几个操作符来指定版本:==
,~=
,>=
和<=
。
在我的程序中,我正在使用setuptools的pkg_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: ==
, ~=
, >=
, and <=
.
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 ==
, ~=
, >=
, and <=
operators the exact same way pip does? If not, is there an alternative that does?
答案1
得分: 1
pip 在内部使用 packaging 库 处理 版本规范,因此我建议您在可能的情况下也使用这个库。
setuptools 的 pkg_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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论