python 获取各pkg版本_Python pkg_resources.get_distribution方法代碼示例

本文详细介绍了Python中pkg_resources.get_distribution方法的用途和常见代码示例。通过示例展示了如何获取包的版本信息,适用于检查已安装包的版本,用于升级或验证版本一致性。示例涵盖了不同的使用场景,如检查更新、显示版本信息等。
摘要由CSDN通过智能技术生成

本文整理匯總了Python中pkg_resources.get_distribution方法的典型用法代碼示例。如果您正苦於以下問題:Python pkg_resources.get_distribution方法的具體用法?Python pkg_resources.get_distribution怎麽用?Python pkg_resources.get_distribution使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在模塊pkg_resources的用法示例。

在下文中一共展示了pkg_resources.get_distribution方法的25個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Python代碼示例。

示例1: install_package

​點讚 6

# 需要導入模塊: import pkg_resources [as 別名]

# 或者: from pkg_resources import get_distribution [as 別名]

def install_package(package, version="upgrade"):

from sys import executable

from subprocess import check_call

result = False

if version.lower() == "upgrade":

result = check_call([executable, "-m", "pip", "install", package, "--upgrade", "--user"])

else:

from pkg_resources import get_distribution

current_package_version = None

try:

current_package_version = get_distribution(package)

except Exception:

pass

if current_package_version is None or current_package_version != version:

installation_sign = "==" if ">=" not in version else ""

result = check_call([executable, "-m", "pip", "install", package + installation_sign + version, "--user"])

return result

開發者ID:thingsboard,項目名稱:thingsboard-gateway,代碼行數:19,

示例2: show_version

​點讚 6

# 需要導入模塊: import pkg_resources [as 別名]

# 或者: from pkg_resources import get_distribution [as 別名]

def show_version():

entries = []

entries.append('- Python v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}'.format(sys.version_info))

version_info = discord.version_info

entries.append('- discord.py v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}'.format(version_info))

if version_info.releaselevel != 'final':

pkg = pkg_resources.get_distribution('discord.py')

if pkg:

entries.append(' - discord.py pkg_resources: v{0}'.format(pkg.version))

entries.append('- aiohttp v{0.__version__}'.format(aiohttp))

entries.append('- websockets v{0.__version__}'.format(websockets))

uname = platform.uname()

entries.append('- system info: {0.system} {0.release} {0.version}'.format(uname))

print('\n'.join(entries))

開發者ID:Rapptz,項目名稱:discord.py,代碼行數:18,

示例3: cli

​點讚 6

# 需要導入模塊: import pkg_resources [as 別名]

# 或者: from pkg_resources import get_distribution [as 別名]

def cli(ctx):

"""Check the latest Apio version."""

current_version = get_distribution('apio').version

latest_version = get_pypi_latest_version()

if latest_version is None:

ctx.exit(1)

if latest_version == current_version:

click.secho('You\'re up-to-date!\nApio {} is currently the '

'newest version available.'.format(latest_version),

fg='green')

else:

click.secho('You\'re not updated\nPlease execute '

'`pip install -U apio` to upgrade.',

fg="yellow")

開發者ID:FPGAwars,項目名稱:apio,代碼行數:19,

示例4: install_scripts

​點讚 6

# 需要導入模塊: import pkg_resources [as 別名]

# 或者: from pkg_resources import get_distribution [as 別名]

def install_scripts(distributions):

"""

Regenerate the entry_points console_scripts for the named distribution.

"""

try:

from setuptools.command import easy_install

import pkg_resources

except ImportError:

raise RuntimeError("'wheel install_scripts' needs setuptools.")

for dist in distributions:

pkg_resources_dist = pkg_resources.get_distribution(dist)

install = wheel.paths.get_install_command(dist)

command = easy_install.easy_install(install.distribution)

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值