【发布时间】:2016-12-12 16:43:24
【问题描述】:
我想使用 pkg_resources.require 检查是否所有必需的模块都安装在正确的版本中。一切正常,但如果 pkg_resources 引发 pkg_resource.VersionConflict,我不知道如何打印信息。
此示例将引发异常,因为安装的 ccc 版本是 1.0.0。
dependencies = [
'aaa=0.7.1',
'bbb>=3.6.4',
'ccc>=2.0.0'
]
try:
print(pkg_resources.require(dependencies))
except pkg_resources.VersionConflict:
print ("The following modules caused an error:")
// What do i have to do to print out the currently installed version of ccc and the required version using the returned information from pkg_resourcens//
exit()
【问题讨论】:
-
取决于包。有时
import ccc; print(ccc.__version__)会起作用 -
重点是我想处理 pkg_resources.require 反馈的结果。结果中一定有东西表明只有 ccc 的版本不正确。
-
那么您需要将该对象分配给一个变量。现在你只是在打印后扔掉它。