对于基于 apt 的操作系统,有一个apt-cache show
子命令可以显示有关特定包的所有已知信息,包括版本、依赖项和详细描述。
虽然 pippip show
也有一个子命令,但它只显示以下信息已安装包。(我想这和 pip 和 apt-cache 的“在线”架构有关。)
pip 有没有办法查看有关包的更多信息,而不需要转到吡啶甲酸在网络浏览器中?
答案1
pip
不提供此功能。但是,1. 有一个很酷的包名为yolk
可以查询 PyPI 存储库以获取可用包的元数据。2. PyPI 提供了一个 JSON API,您可以使用所选择的工具进行查询。
1.yolk
使用安装
$ pip2 install yolk
或者
$ pip3 install yolk3k
python2
用户请注意:
看起来原始yolk
包现在在查询 PyPI 包时出现了问题。这可能是由于最近将存储库从https://pypi.python.org到https://pypi.org; 不幸的是,yolk
已经很旧了,而且已经好几年没有更新了。如果你碰巧有python2.7
,请使用它,yolk3k
因为它与 兼容python2.7
:
$ pip2.7 uninstall -y yolk && pip2.7 install yolk3k
(感谢@AnneTheAgile 的提示,请参阅此评论)
查询包的完整元数据(无论是否安装):
$ yolk -M pytest
maintainer:
docs_url: None
requires_python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
maintainer_email:
cheesecake_code_kwalitee_id: None
keywords: test unittest
package_url: http://pypi.python.org/pypi/pytest
author: Holger Krekel, Bruno Oliveira, Ronny Pfannschmidt, Floris Bruynooghe, Brianna Laugher, Florian Bruhin and others
author_email:
download_url:
platform: unix
version: 3.5.0
cheesecake_documentation_id: None
_pypi_hidden: False
description:
... # here comes the long README contents
release_url: http://pypi.python.org/pypi/pytest/3.5.0
downloads: {'last_month': 0, 'last_week': 0, 'last_day': 0}
_pypi_ordering: 69
requires_dist: ['py (>=1.5.0)', 'six (>=1.10.0)', 'setuptools', 'attrs (>=17.4.0)', 'more-itertools (>=4.0.0)', 'pluggy (<0.7,>=0.5)', 'funcsigs; python_version < "3.0"', 'colorama; sys_platform == "win32"']
classifiers: ['Development Status :: 6 - Mature', 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Operating System :: MacOS :: MacOS X', 'Operating System :: Microsoft :: Windows', 'Operating System :: POSIX', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Topic :: Software Development :: Libraries', 'Topic :: Software Development :: Testing', 'Topic :: Utilities']
name: pytest
bugtrack_url: https://github.com/pytest-dev/pytest/issues
license: MIT license
summary: pytest: simple powerful testing with Python
home_page: http://pytest.org
cheesecake_installability_id: None
仅查询选定的元数据字段:
$ yolk -M pytest -f author,requires_python
requires_python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
author: Holger Krekel, Bruno Oliveira, Ronny Pfannschmidt, Floris Bruynooghe, Brianna Laugher, Florian Bruhin and others
现在您知道如何获取包描述:
$ yolk -M pkgname -f long_description
2.查询PyPI的JSON API
curl
上面带有+ 的例子jq
:
$ curl -sH "accept: application/json" https://pypi.org/pypi/pytest/json | jq -r '.info.author, .info.requires_python'
Holger Krekel, Bruno Oliveira, Ronny Pfannschmidt, Floris Bruynooghe, Brianna Laugher, Florian Bruhin and others
>=3.5
打印所有包元数据:
$ curl -sH "accept: application/json" https://pypi.org/pypi/pytest/json | jq -r '.info | keys[] as $key | "\($key): \(.[$key])"'
author: Holger Krekel, Bruno Oliveira, Ronny Pfannschmidt, Floris Bruynooghe, Brianna Laugher, Florian Bruhin and others
author_email:
bugtrack_url: null
...