代码之家  ›  专栏  ›  技术社区  ›  andrei

如何让setuptools安装一个不在PyPI上的包?

  •  128
  • andrei  · 技术社区  · 14 年前

    我刚刚开始使用setuptools和virtualenv。我的包需要最新的python gearman,它只能从GitHub获得。PyPI上的python gearman版本是一个旧版本。Github的源代码是setuptools兼容的,例如有setup.py等。有没有办法让setuptools下载并安装新版本,而不是在PyPI上查找并安装旧版本?

    仅供参考,新的python gearman http://github.com/mtai/python-gearman

    4 回复  |  直到 14 年前
        1
  •  161
  •   devin_s    7 年前

    关键是告诉easy\u install在哪里可以下载包。在这种情况下,可以在url中找到它 http://github.com/mtai/python-gearman/tarball/master . 然而,这个链接本身是不起作用的,因为easy\u install不能仅仅通过查看URL来判断它将得到什么。

    把它改成 http://github.com/mtai/python-gearman/tarball/master#egg=gearman-2.0.0beta

    最后一步是将URL添加到包的依赖链接中,例如:

    setup(
       ...
       dependency_links = ['http://github.com/mtai/python-gearman/tarball/master#egg=gearman-2.0.0beta']
    )
    

    现在,在安装软件包时,easy\u install会发现有一个“gearman 2.0.0beta”可从该URL下载,如果您指定“gearman>=2.0.0beta版。。

    (通常,这类事情的处理方式是在PyPI页面上包含一个到可下载源的链接;在本例中,如果gearman包的作者包含了上面这样的链接,那么您就已经被设置好了。通常,人们用“myproject dev”标记开发版本,然后使用“myproject>=somever,==dev',因此如果没有somever或更高版本的软件包,easy\u install将尝试签出或下载该版本。)

    您需要指定 --process-dependency-links pip . 请注意,依赖关系链接处理已被弃用,并将在将来的版本中删除。

        2
  •  70
  •   Community CDub    8 年前

    你可以用 pip install protocol+location[@tag][#egg=Dependency]

    吉特

    pip install git+https://github.com/username/repo.git
    pip install git+https://github.com/username/repo.git@MyTag
    pip install git+https://github.com/username/repo.git@MyTag#egg=ProjectName
    

    水银的

    pip install hg+https://hg.myproject.org/MyProject/
    

    SVN公司

    pip install svn+svn://svn.myproject.org/svn/MyProject
    

    pip install bzr+http://bzr.myproject.org/MyProject/trunk
    

    支持以下协议: [+git, +svn, +hg, +bzr]

    @tag

    #egg=name 允许您指定项目作为其他项目的依赖项。

    顺序必须始终正确 @tag#egg=name .

    专用存储库

    您还可以通过将协议更改为SSH从私有存储库进行安装( ssh:// )以及添加适当的用户( git@ ):

    git+ssh://git@github.com/username/my_private_repo
    

    您还可以使用用户名/密码从私有存储库安装。

    git+https://<username>:<password>@github.com/<user>/<repo>.git
    

    Github提供了创建 personal OAuth tokens

    git+https://<oauth token>:x-oauth-basic@github.com/<user>/<repo>.git
    

    要求.txt

    requirements.txt

    要求.txt

    package1
    package2==1.0.2
    package3>=0.0.4
    git+https://github.com/username/repo.git
    

    pip -r requirements.txt .

    包括需求文件

    需求文件可以包括其他需求文件:

    需求文档.txt

    sphinx
    -r requirements-dev.txt
    

    some-dev-tool
    -r requirements.txt
    

    要求.txt

    包装1
    包装2==1.0.2
    包装3>=0.0.4
    

    需求文件可以安装中指定的依赖项 setup.py 使用以下命令:

    -e .
    

    设置.py 也可以使用与上面相同的语法从存储库安装,但是使用 dependency_links 中提到的值 this answer

    参考文献:

    https://pip.pypa.io/en/latest/user_guide.html#installing-packages https://pip.pypa.io/en/latest/reference/pip_install.html

        3
  •  22
  •   Community CDub    4 年前

    因为我不得不做同样的事情,所以我找到了另一种方法 pip --process-dependency-links 计划在中删除 皮普 19.0根据 this comment .

    皮普

    the description

    基于URL的最小查找:

    https://github.com/pypa/pip/archive/1.3.1.zip#sha1=da9234ee9982d4bbb3c72346a6de940a148ea686

    setup.py 看起来像

    setup(
       ...
       install_requires = [
       ...
       'python-gearman @ https://github.com/mtai/python-gearman/archive/master.zip'
       ...
       ]
    )
    

    注意,链接是一个归档文件,也可以是存储库的特定版本或分支,如前所述 in this answer . 另外,请参阅与其他存储库主机一起工作的答案。

    据我所知,更新依赖关系的最简单方法是使用 pip install -I .

        4
  •  6
  •   ThiefMaster    10 年前

    香草 setuptools 不支持直接从git存储库下载,但您可以使用 下载源 来自该页面的链接,如:

    easy_install http://github.com/mtai/python-gearman/tarball/master