如何以编程方式检查python软件包是否为最新版本?

如何以编程方式检查python软件包是否为最新版本?,第1张

如何以编程方式检查python软件包是否为最新版本? 快速版本(仅检查软件包)

下面的代码使用不可用的版本(如)调用该软件包

pip installpackage_name==random
。该调用将返回所有可用版本。该程序将读取最新版本。

然后,程序运行

pip show package_name
并获取软件包的当前版本。

如果找到匹配项,则返回True,否则返回False。

考虑到它是一个可靠的选择

pip

import subprocessimport sysdef check(name):    latest_version = str(subprocess.run([sys.executable, '-m', 'pip', 'install', '{}==random'.format(name)], capture_output=True, text=True))    latest_version = latest_version[latest_version.find('(from versions:')+15:]    latest_version = latest_version[:latest_version.find(')')]    latest_version = latest_version.replace(' ','').split(',')[-1]    current_version = str(subprocess.run([sys.executable, '-m', 'pip', 'show', '{}'.format(name)], capture_output=True, text=True))    current_version = current_version[current_version.find('Version:')+8:]    current_version = current_version[:current_version.find('\n')].replace(' ','')    if latest_version == current_version:        return True    else:        return False

以下代码要求

pip list --outdated

import subprocessimport sysdef check(name):    reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'list','--outdated'])    outdated_packages = [r.depre().split('==')[0] for r in reqs.split()]    return name in outdated_packages


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5648137.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存