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

and*_*rei 137 python distutils setuptools pypi

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

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

PJ *_*Eby 153

关键是告诉easy_install可以下载包的位置.在这种特殊情况下,可以在网址http://github.com/mtai/python-gearman/tarball/master找到它.但是,该链接本身不起作用,因为easy_install只能通过查看URL将会得到什么.

通过将其更改为http://github.com/mtai/python-gearman/tarball/master#egg=gearman-2.0.0beta,easy_install将能够识别包名称及其版本.

最后一步是将URL添加到包的dependency_links中,例如:

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

现在,当您的软件包正在安装时,easy_install将发现可以从该URL下载"gearman 2.0.0beta",并且如果您指定"gearman> = 2.0.0beta",请高兴地通过PyPI上的那个选择它在你的依赖..

(通常情况下,完成此类操作的方法是在一个PyPI页面上包含一个链接到可下载源;在这种情况下,如果gearman包的作者包含了如上所述的链接,那么你已经设置好了通常,人们使用'myproject-dev'标记开发版本然后人们使用'myproject> = somever,== dev'的要求,这样如果没有某个或更高的包,easy_install将尝试检查或下载该版本.)

您需要在使用--process-dependency-links时指定pip.请注意,已弃用依赖关系链接处理,将在以后的版本中将其删除.

  • 你还需要install_requires ='gearman> = 2.0.0beta'; 你有这个吗? (14认同)
  • 它对我不起作用,在PyPI上的现有版本上使用`beta`后缀,它仍将从PyPI安装包,而不是在`dependency_links`中定义的包.如果您尝试使用`#egg = package-version`设置比PyPI上存在的版本更高的版本,则安装工具将抱怨"无法找到满足要求的版本"错误以及可用的所有版本的列表的PyPI.请注意,我正在尝试使用`sdist`构建我的包,然后使用`pip install http:// url/to/my/generated/tar`安装它. (3认同)
  • 从--pip 19开始,已删除--process-dependency-links!参见:https://github.com/pypa/pip/issues/6162 (2认同)

Reb*_*ebs 64

您可以使用pip install protocol+location[@tag][#egg=Dependency]pip直接从源代码安装格式.

混帐

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
Run Code Online (Sandbox Code Playgroud)

水银

pip install hg+https://hg.myproject.org/MyProject/
Run Code Online (Sandbox Code Playgroud)

SVN

pip install svn+svn://svn.myproject.org/svn/MyProject
Run Code Online (Sandbox Code Playgroud)

BZR

pip install bzr+http://bzr.myproject.org/MyProject/trunk
Run Code Online (Sandbox Code Playgroud)

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

版本

@tag 允许您指定要签出的特定版本/标记.

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

订单必须始终如此@tag#egg=name.

私人存储库

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

git+ssh://git@github.com/username/my_private_repo
Run Code Online (Sandbox Code Playgroud)

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

git+https://<username>:<password>@github.com/<user>/<repo>.git
Run Code Online (Sandbox Code Playgroud)

Github提供了创建可以循环的个人OAuth令牌的功能

git+https://<oauth token>:x-oauth-basic@github.com/<user>/<repo>.git
Run Code Online (Sandbox Code Playgroud)

requirements.txt

requirements.txt 用于指定项目依赖项:

requirements.txt

package1
package2==1.0.2
package3>=0.0.4
git+https://github.com/username/repo.git
Run Code Online (Sandbox Code Playgroud)

这些不会随包自动安装,必须与命令一起安装pip -r requirements.txt.

包括需求文件

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

要求-Docs.txt的

sphinx
-r requirements-dev.txt
Run Code Online (Sandbox Code Playgroud)

要求-dev.txt

some-dev-tool
-r requirements.txt
Run Code Online (Sandbox Code Playgroud)

requirements.txt

package1
package2==1.0.2
package3>=0.0.4
git+https://github.com/username/repo.git
Run Code Online (Sandbox Code Playgroud)

setup.py

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

-e .
Run Code Online (Sandbox Code Playgroud)

setup.py也可以使用与上面相同的语法从存储库安装,但使用此答案中dependency_links提到的值.

参考文献:

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

  • setup.py可以从存储库安装.只需搜索'setup.py dependency_links' (2认同)

小智 17

正如我刚刚做同样的事情,我发现了另一种方式来做到这一点作为pip--process-dependency-links被安排在除去pip按照19.0 此评论.

pip 18.1包括以下功能

允许将PEP 508 URL要求用作依赖项.

从PEP 508 的描述中,这种URL依赖关系的语法如下所示:

基于URL的最小查找:

pip @ 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'
   ...
   ]
)
Run Code Online (Sandbox Code Playgroud)

请注意,该链接是一个存档文件,也可以是存储库的特定版本或分支,如本答案中所述.另外,请参阅与其他存储库主机一起使用的答案.

据我所知,更新依赖关系的最简单方法是pip install -I .在从其目录安装软件包时使用.


Ned*_*ily 6

Vanilla setuptools不支持直接从git存储库下载,但您可以使用该页面中的一个Download Source链接,例如:

easy_install http://github.com/mtai/python-gearman/tarball/master
Run Code Online (Sandbox Code Playgroud)

  • 正如我在上面的评论中提到的,setup.py提供了dependency_links,允许您从gti存储库下载 (2认同)