How to check if python package is latest version programmatically?

后端 未结 7 1695
南旧
南旧 2020-12-18 18:42

How do you check if a package is at its latest version programmatically in a script and return a true or false?

I can check with a script like this:



        
相关标签:
7条回答
  • 2020-12-18 19:15

    Latest version:

    My project luddite has this feature:

    >>> import luddite
    >>> luddite.get_version_pypi("gekko")
    '0.2.3'
    

    Installed version:

    The canonical way to check installed version is just to access the __version__ attribute of the top-level namespace:

    >>> import gekko
    >>> gekko.__version__
    '0.2.0'
    

    Unfortunately not all projects set this attribute. When they don't, you can use pkg_resources to dig it out from the metadata:

    >>> import pkg_resources
    >>> pkg_resources.get_distribution("gekko").version
    '0.2.0'
    
    0 讨论(0)
提交回复
热议问题