Python How can I get the version number from a .whl file

心已入冬 提交于 2019-12-24 01:53:27

问题


Because of some custom logging I would like to get the version number from a wheel file.

I could of course just parse the filename, but my guess is there would be a better way to do this.


回答1:


What I did for now is:

Get the package info and put it into a dict:

def get_package_info():
    info_dict = {}
    with open(os.path.join(glob.glob("./*.egg-info")[0], "PKG-INFO"), "r") as info:
        for i in info:
            i = i.split(":")
            info_dict[i[0].strip()] = i[1].strip()

        return info_dict

Now I can get the Verion from this dictionary.

If someone does have a better approach at this, please let me know.



来源:https://stackoverflow.com/questions/42019184/python-how-can-i-get-the-version-number-from-a-whl-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!