1

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()
4

1 に答える 1

1

とった。例外を変数に割り当てて、それを操作する必要があります。コードは次のとおりです。

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()
于 2016-12-12T20:42:43.750 に答える