Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python轻松安装更新报告_Python_Easy Install - Fatal编程技术网

Python轻松安装更新报告

Python轻松安装更新报告,python,easy-install,Python,Easy Install,有没有一种简单的方法可以获取通过easy_install安装的所有Python库的报告,这些Python库都有一个更新的版本可用?我不想简单地在已知已安装库的列表上重新运行easy_install,因为较新的库可能有不向后兼容的更改。我想获得一个列表,以便快速查看更改的内容,并检查新版本以检查任何潜在的冲突更改。这里有一个快速脚本,用于扫描easy install.pth文件并打印已安装软件包的较新版本列表。您可以对其进行自定义,以仅显示可用的最新版本(最大值为已解析的\u版本),调整输出格式,

有没有一种简单的方法可以获取通过easy_install安装的所有Python库的报告,这些Python库都有一个更新的版本可用?我不想简单地在已知已安装库的列表上重新运行easy_install,因为较新的库可能有不向后兼容的更改。我想获得一个列表,以便快速查看更改的内容,并检查新版本以检查任何潜在的冲突更改。

这里有一个快速脚本,用于扫描
easy install.pth
文件并打印已安装软件包的较新版本列表。您可以对其进行自定义,以仅显示可用的最新版本(最大值为
已解析的\u版本
),调整输出格式,等等:

#!/usr/bin/env python
import os, sys
from distutils import sysconfig
from pkg_resources import Requirement
from setuptools.package_index import PackageIndex

index = PackageIndex()
root = sysconfig.get_python_lib()
path = os.path.join(root, 'easy-install.pth')
if not os.path.exists(path):
    sys.exit(1)
for line in open(path, 'rb'):
    if line.startswith('import sys'):
        continue
    path = os.path.join(root, line.strip(), 'EGG-INFO', 'PKG-INFO')
    if not os.path.exists(path):
        continue
    lines = [r.split(':', 1) for r in open(path, 'rb').readlines() if ':' in r]
    info = dict((k.strip(), v.strip()) for k, v in lines)
    print '%s %s updates..' % (info['Name'], info['Version'])
    spec = Requirement.parse(info['Name'] + '>' + info['Version'])
    index.find_packages(spec)
    versions = set([
        (d.parsed_version, d.version) for d in index[spec.key] if d in spec
        ])
    if versions:
        for _, version in sorted(versions):
            print '\t', version
    else:
        print '\tnone'
用法:

% easy_install networkx==1.3
% easy_install gdata==2.0.5
% ./pkgreport
networkx 1.3 updates..
        1.4rc1
        1.4
gdata 2.0.5 updates..
        2.0.6
        2.0.7
        2.0.8
        2.0.9
        2.0.14