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

问题:我如何让setuptools安装不在PyPI上的软件包?

我刚刚开始使用setuptools和virtualenv。我的软件包需要最新的python-gearman,该工具仅可从GitHub获得。PyPI上的python-gearman版本是一个旧版本。Github源代码与setuptools兼容,即具有setup.py等。是否可以通过一种方法来使setuptools下载并安装新版本,而不是在PyPI上寻找并安装旧版本?

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

I’ve just started working with setuptools and virtualenv. My package requires the latest python-gearman that is only available from GitHub. The python-gearman version that’s on PyPI is an old one. The Github source is setuptools-compatible, i.e. has setup.py, etc. Is there a way to make setuptools download and install the new version instead of looking for it on PyPI and installing the old one?

FYI, the new python-gearman is http://github.com/mtai/python-gearman


回答 0

关键是告诉easy_install软件包可以在哪里下载。在这种情况下,可以在url 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']
)

现在,在安装您的软件包时,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。请注意,不赞成使用依赖项链接处理,在以后的版本中将删除它。

The key is to tell easy_install where the package can be downloaded. In this particular case, it can be found at the url http://github.com/mtai/python-gearman/tarball/master. However, that link by itself won’t work, because easy_install can’t tell just by looking at the URL what it’s going to get.

By changing it to http://github.com/mtai/python-gearman/tarball/master#egg=gearman-2.0.0beta instead, easy_install will be able to identify the package name and its version.

The final step is to add the URL to your package’s dependency_links, e.g.:

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

Now, when YOUR package is being installed, easy_install will discover that there is a “gearman 2.0.0beta” available for download from that URL, and happily pick it over the one on PyPI, if you specify “gearman>=2.0.0beta” in your dependencies..

(Normally, the way this sort of thing is done is to include a link on one’s PyPI page to the downloadable source; in this case, if the author of the gearman package had included a link like the above, you’d be already set. Typically, people mark the development version with ‘myproject-dev’ and then people use a requirement of ‘myproject>=somever,==dev’, so that if there isn’t a package of somever or higher, easy_install will try to check out or download the release.)

You’ll need to specify --process-dependency-links when using pip. Note that dependency links processing has been deprecated and will be removed in a future release.


回答 1

您可以使用该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

水银

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

SVN

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

z

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提供了创建可循环使用的个人OAuth令牌的功能

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

requirements.txt

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

requirements.txt

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

这些不是随软件包一起自动安装的,必须通过命令安装pip -r requirements.txt

包括需求文件

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

requirements-docs.txt

sphinx
-r requirements-dev.txt

requirements-dev.txt

some-dev-tool
-r requirements.txt

requirements.txt

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

setup.py

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

-e .

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

参考文献:

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

You can use the pip install protocol+location[@tag][#egg=Dependency] format to install directly from source using pip.

Git

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

Mercurial

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

SVN

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

Bzr

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

The following protocols are supported: [+git, +svn, +hg, +bzr]

Versions

@tag lets you specify a specific version/tag to check out.

#egg=name lets you specify what the project is as a dependency for others.

The order must always be @tag#egg=name.

Private Repositories

You can also install from private repositories by changing the protocol to SSH (ssh://) and adding an appropriate user (git@):

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

You can also install from private repositories with a username / password.

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

Github provides the ability to create personal OAuth tokens which can be cycled

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

requirements.txt

requirements.txt is used to specify project dependencies:

requirements.txt

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

These are not installed automatically with the package and must be installed with the command pip -r requirements.txt.

Including requirements files

Requirements files can include other requirements files:

requirements-docs.txt

sphinx
-r requirements-dev.txt

requirements-dev.txt

some-dev-tool
-r requirements.txt

requirements.txt

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

setup.py

Requirements files can install dependencies specified in setup.py with the following command:

-e .

setup.py can also install from repositories using the same syntax as above, but using the dependency_links value as mentioned in this answer.

References:

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


回答 2

正如我刚刚做同样的事情,我发现了另一种方式来做到这一点作为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'
   ...
   ]
)

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

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

As I just had to do the same thing, I found another way to do this as pip‘s --process-dependency-links are scheduled to be removed in pip 19.0 according to this comment.

pip 18.1 includes the following feature

Allow PEP 508 URL requirements to be used as dependencies.

From the description of PEP 508, the syntax for such URL dependencies looks like:

A minimal URL based lookup:

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

So in your setup.py it would look like

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

Notice, the link is an archive file and could also be a specific release or branch of a repository as described in this answer. Also, see that answer for working with other repository hosts.

To the best of my knowledge, the easiest way to update the dependency is by using pip install -I . when installing your package from its directory.


回答 3

Vanilla setuptools不支持直接从git存储库下载,但是您可以使用该页面上的“ 下载源”链接之一,例如:

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

Vanilla setuptools does not support downloading directly from a git repository but you can use one of the Download Source links from that page, like:

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