如何使用 pip 搜索可用的 Python 包?

我希望能够使用 pip(在终端上)搜索可用的 Python 包。我希望在 Ubuntu 中有一个类似于 apt-cache的功能。更确切地说,我愿意

  1. 能够搜索给定一个术语的包(类似于 apt-cache search [package-name]) ,以及
  2. 列出所有可用的包裹。
182449 次浏览

要搜索包,请发出命令

pip search [package-name]
  1. 使用 pip search QUERY进行搜索

    使用 pip helppip help COMMAND了解所有可用命令及其选项。

  2. 您可以在这里找到软件包的完整列表:

    Https://pypi.org/

    在这里可以找到一个标记更简单、更容易自动消费的索引:

    Https://pypi.org/simple/

若要查看所有可用包的列表,请尝试运行

pip search *

如果你不想经常使用 Pip 搜索,它可以解决你的问题。但是在经常使用之后,我发现它很难阅读,使用速度很慢,而且它没有显示我有时需要的信息(上传时间,许可证,大小等) ,所以我最终写了一个替代品,我认为它变得相当不错。

它被称为 yip,它就像类固醇中的 pip search。它支持正则表达式搜索,彩色输出和菜单系统,使安装从搜索结果非常容易。如果你想知道更多或看到一个屏幕截图 去 GitHub 看看

截至2020年12月,pip search将不工作(更多)。

目前可行的解决方案是在线搜索,在: https://pypi.org/(参考也提供了以前的意见)。

如果有人出现以下错误:

xmlrpc.client.Fault: <Fault -32500: "RuntimeError: PyPI's XMLRPC API has been temporarily
disabled due to unmanageable load and will be deprecated in the near future.
See https://status.python.org/ for more information.">

# 5216所述:

作为更新: XMLRPC 搜索仍然是禁用的。

因为:

正如在 # 5216(评论)中所指出的,一组服务器正在到达 pip 搜索入口点,以至于 PyPI 无法用 pip 搜索的当前架构来维持这种负载。

更新: 作为使用 PyPI 注册表的 pip的替代 CLI,可以使用 :

$ poetry search <package>

截至2020年12月14日,pip search功能已被禁用:

$ pip search cast
ERROR: XMLRPC request failed [code: -32500]
RuntimeError: PyPI's XMLRPC API is currently disabled due to unmanageable load and will be deprecated in the near future. See https://status.python.org/ for more information.

替代品

这里有一个叫做 < em > < strong > pip _ search 的小工具,我刚刚发现它可以做一个简单的搜索,但它可以完成工作。

这是 pip_search v0.0.6输出:

$ pip_search pulsemixer
----------------  -------------------------------------------------------------------------------
Name              Description


pulsemixer        pulsemixer - CLI and curses mixer for PulseAudio
pulsectl-asyncio  Asyncio frontend for the pulsectl Python bindings of libpulse
pulsectl          Python high-level interface and ctypes-based bindings for PulseAudio (libpulse)
----------------  -------------------------------------------------------------------------------

更新

pip_search已经更新,每个文件夹是一个可点击(CTRL + 点击)每个项目的 URL,现在看起来像这样:

$ pip_search pulsemixer
🐍 https://pypi.org/search/?q=pulsemixer 🐍
┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Package             ┃ Version ┃ Released     ┃ Description                                                                     ┃
┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ 📂 pulsemixer       │ 1.5.1   │ Apr 11, 2020 │ pulsemixer - CLI and curses mixer for PulseAudio                                │
│ 📂 pulsectl-asyncio │ 0.1.7   │ Jun 13, 2021 │ Asyncio frontend for the pulsectl Python bindings of libpulse                   │
│ 📂 pulsectl         │ 21.5.18 │ May 22, 2021 │ Python high-level interface and ctypes-based bindings for PulseAudio (libpulse) │
└─────────────────────┴─────────┴──────────────┴─────────────────────────────────────────────────────────────────────────────────┘

要安装它,只需键入:

pip install pip_search


还有一个我刚刚试过的工具叫做 < em > pypisearch

要安装它,只需键入: pip install pypisearch

它的工作原理是这样的:

$ python -m pypisearch pulsemixer
pulsemixer (1.5.1)        [installed 1.5.0] pulsemixer - CLI and curses mixer for PulseAudio
pulsectl-asyncio (0.1.5)  Asyncio frontend for the pulsectl Python bindings of libpulse
pulsectl (21.3.4)         Python high-level interface and ctypes-based bindings for PulseAudio (libpulse)

用途: pip show < package _ name >

2020年12月以后,search不工作了,但是 index工作了。

pip index versions <package_name>

注意: pip index目前是一个实验性命令。它可能在未来的版本中被删除/更改而没有事先警告。

编辑: (也可以使用 pip index -vv versions <package>获得详细的输出。)

只需安装要搜索的软件包的不存在版本即可。通过这种方式,您不仅可以找到稳定版本,还可以找到像 1.2.3a2这样的 alpha 和 beta 版本。

pip install [package]==666.666.666