【问题标题】:How is Pip able to install packages by name or URL?Pip 如何通过名称或 URL 安装包?
【发布时间】:2015-08-08 16:03:05
【问题描述】:

我知道你可以使用 pip 按名称安装 Python 包,但我最近发现你可以install Python packages by URL。例如:

pip install http://www.crummy.com/software/BeautifulSoup/unreleased/4.x/BeautifulSoup-4.0b.tar.gz

Pip 是如何做到这一点的?如果包名看起来像 URL 怎么办?

【问题讨论】:

  • 提示:pip 是开源的
  • 什么时候包名看起来像一个 URL?
  • @OliverCharlesworth Like Martijn Peters 指出,模块名称真的不能看起来像 URL。

标签: python python-2.7 pip


【解决方案1】:

如有疑问,只需检查来源。 Pip 在他们的下载模块中有一个函数来检查名称输入是否看起来像一个 URL。

def is_url(name):
    """Returns true if the name looks like a URL"""
    if ':' not in name:
        return False
    scheme = name.split(':', 1)[0].lower()
    return scheme in ['http', 'https', 'file', 'ftp'] + vcs.all_schemes

编辑:正如@MartijnPieters 指出的那样,有一些标准可以命名模块,并且不允许在名称中使用冒号。

如果您尝试将 http: 放在模块名称的开头,那么您可能不是在编写我想下载的软件。

【讨论】:

  • http 和一个冒号。 Pip 有大约 65 个以http 开头的包。他们都没有在名称中使用冒号(无论如何都是不允许的)。
  • @MartijnPieters 对。或任何其他或任何其他协议标头。
猜你喜欢
  • 2017-02-04
  • 1970-01-01
  • 2022-01-05
  • 2020-09-14
  • 1970-01-01
  • 1970-01-01
  • 2022-01-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多