【问题标题】:Get pip to work with git and github repository让 pip 使用 git 和 github 存储库
【发布时间】:2013-01-22 03:34:18
【问题描述】:

出于开发原因,我正在编写一个 python 应用程序,该应用程序依赖于托管在 github 存储库(从未在 pypi 中)上的另一个应用程序。

让我们给他们打电话:

  • 正在编写的应用程序:AppA
  • github 中的应用程序:AppB

在 App A 中,setup.py 是这样的:

# coding=utf-8
import sys
try:
    from setuptools import setup, find_packages
except ImportError:
    import distribute_setup
    distribute_setup.use_setuptools()
    from setuptools import setup, find_packages

setup(
    ...
    install_requires=[
        # other requirements that install correctly
        'app_b==0.1.1'
    ],
    dependency_links=[
        'git+https://github.com/user/app_b.git@0.1.1#egg=app_b-0.1.1'
    ]
)

现在AppA 正在由Jenkins CI 构建,每次推送我都会失败,因为抛出了下一个错误:

error: Download error for git+https://github.com/user/app_b.git@0.1.1: unknown url type: git+https

有趣的是,这只发生在 Jenkins 中,它在我的计算机上完美运行。我尝试了 github 提供的其他两个 SSH url,甚至都没有考虑下载。

现在,AppA 包含在同样由 Jenkins 构建的项目的需求文件中,因此不能通过 pip install AppA pip install AppB 手动安装依赖项,依赖项会通过包含在 @987654329 中自动安装@。

有没有办法让 pip 和 git 与 github url 一起工作?

任何帮助将不胜感激:)

提前致谢!

【问题讨论】:

  • 你确定 Jenkins 使用 pip 吗?如果是,是否支持此功能的版本?
  • @Gerard 你的 Jenkins 盒子使用什么版本的 pip? pip --version 应该为您提供该信息。袖手旁观,看起来像0.8.2之前的版本,不支持https方案。

标签: python django git github pip


【解决方案1】:

问题不在于pip,而在于setuptools。负责setup() 调用的是setuptools 包(setuptools 或分发项目)。

setuptoolsdistribute 都不理解那种 url,他们理解 tarballs/zip 文件。

尝试指向 Github 的下载 url - 通常是一个 zip 文件。

您的dependency_links 条目可能如下所示:

dependency_links=[
    'https://github.com/user/app_b/archive/0.1.1.zip#egg=app_b-0.1.1'
]

欲了解更多信息,请查看http://peak.telecommunity.com/DevCenter/setuptools#dependencies-that-aren-t-in-pypi

【讨论】:

  • 除了这个答案之外,在我的情况下,如果requires 中的此类包采用package==version 的形式,则永远无法安装该包,但它使用package 工作;也就是只有包名没有版本
  • 如何将私有存储库的分支添加为依赖链接?这毕竟是使用 git+[https|ssh] 风格要求的主要原因之一
【解决方案2】:

来自pip documentation -

pip currently supports cloning over git, git+http and git+ssh:

git+git://git.myproject.org/MyProject#egg=MyProject
git+http://git.myproject.org/MyProject#egg=MyProject
git+ssh://git.myproject.org/MyProject#egg=MyProject

尝试将git+https 替换为git+git

【讨论】:

  • 对不起,这不起作用。它可以在本地工作,但不能在 Jenkins 内部工作 :( 我正在努力解决问题。无论如何,谢谢
  • git+https 应该得到支持,尽管有文档。至少根据source。这一直出现在 pip 0.8.2 中。
  • 我只是说错误显示的内容 - unknown url type: git+https。必须是一些旧版本的 pip。
【解决方案3】:

我在 2019 年遇到了同样的问题,但原因不同。 dependency_links 在 pip 中不再支持(使用 pip>=20.0.0 进行测试)。对于我的情况,我使用 install_requirements 解决了这个问题并定义了一个直接引用(参见 pip 手册 direct reference)。

...
install_requirements = [
    <dependencyname> @ git+<url of dependency repository>@<branchname or tag>
]

我在https://gitlab.rhrk.uni-kl.de/scheliga/thepackage 创建了一个名为 thepackage 的公共示例存储库以获取更多详细信息。

【讨论】:

    猜你喜欢
    • 2018-11-29
    • 1970-01-01
    • 2015-12-21
    • 1970-01-01
    • 2012-12-19
    • 1970-01-01
    • 2022-08-08
    • 2015-12-05
    • 1970-01-01
    相关资源
    最近更新 更多