我想使用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()
答案 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 as version_error:
print("The following modules caused an error:")
print("Version installed :", version_error.dist)
print("Version required :", version_error.req)
exit()