Setuptools无法使用dependency_links中的链接 [英] Setuptools unable to use link from dependency_links

查看:62
本文介绍了Setuptools无法使用dependency_links中的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试安装配置了以下设置的软件包:

I've been trying to install a package with the following setup configured:

setup(
    packages=find_packages(),
    include_package_data=True,
    install_requires=[
        'Django==1.5.1',
        'xhtml2pdf',
    ],
    dependency_links=[
        'https://github.com/chrisglass/xhtml2pdf/zipball/28d12fcaafc4c47b13f1f6f42c2bfb73f90cc947#egg=xhtml2pdf',
    ],
)

但是,它从PyPi安装XHTML2PDF软件包,而不使用指定的链接.根据输出(我使用pip install -vvv package.tar.gz运行安装),它要么无法从链接(在代码中的// 1处)解析版本,要么我没有指定正确的项目名称(在代码):

However it installs the XHTML2PDF package from PyPi, instead of using the specified link. According to the output (I ran the install using pip install -vvv package.tar.gz), it could either not parse the version from the link (at // 1 in code), or I've not specified the correct project name (at // 2 in code):

Downloading/unpacking xhtml2pdf (from mypackage==1.3)
  Getting page https://pypi.python.org/simple/xhtml2pdf/
  URLs to search for versions for xhtml2pdf (from mypackage==1.3):
  * https://pypi.python.org/simple/xhtml2pdf/
  * https://github.com/chrisglass/xhtml2pdf/zipball/28d12fcaafc4c47b13f1f6f42c2bfb73f90cc947#egg=xhtml2pdf
  Getting page https://github.com/chrisglass/xhtml2pdf/zipball/28d12fcaafc4c47b13f1f6f42c2bfb73f90cc947
  Analyzing links from page https://pypi.python.org/simple/xhtml2pdf/
    Found link https://pypi.python.org/packages/source/x/xhtml2pdf/xhtml2pdf-0.0.1.tar.gz#md5=9f83a2bcb67858aca9e058761f3bea7b (from https://pypi.python.org/simple/xhtml2pdf/), version: 0.0.1
    Found link https://pypi.python.org/packages/source/x/xhtml2pdf/xhtml2pdf-0.0.2.tar.gz#md5=d640ccb9470942fd2e6d3ae740c27dc1 (from https://pypi.python.org/simple/xhtml2pdf/), version: 0.0.2
    Found link https://pypi.python.org/packages/source/x/xhtml2pdf/xhtml2pdf-0.0.1.zip#md5=4ad41c845735ae14da99085311d84c00 (from https://pypi.python.org/simple/xhtml2pdf/), version: 0.0.1
    Found link https://pypi.python.org/packages/source/x/xhtml2pdf/xhtml2pdf-0.0.4.zip#md5=5f035cd6532bef99b7d35054caaa6ef7 (from https://pypi.python.org/simple/xhtml2pdf/), version: 0.0.4
    Found link https://pypi.python.org/packages/source/x/xhtml2pdf/xhtml2pdf-0.0.3.zip#md5=32599c74f26f57ebd002765741ec64f7 (from https://pypi.python.org/simple/xhtml2pdf/), version: 0.0.3
    Found link https://pypi.python.org/packages/source/x/xhtml2pdf/xhtml2pdf-0.0.2.zip#md5=4047a8234eb6b77591d526dcb1f60161 (from https://pypi.python.org/simple/xhtml2pdf/), version: 0.0.2
    Found link https://pypi.python.org/packages/source/x/xhtml2pdf/xhtml2pdf-0.0.3.tar.gz#md5=13b0d6059b72c994473fddfa7a528451 (from https://pypi.python.org/simple/xhtml2pdf/), version: 0.0.3
    Found link https://pypi.python.org/packages/source/x/xhtml2pdf/xhtml2pdf-0.0.5.zip#md5=8db99aae8536436a2b7b0b3987197b99 (from https://pypi.python.org/simple/xhtml2pdf/), version: 0.0.5
    Found link https://pypi.python.org/packages/source/x/xhtml2pdf/xhtml2pdf-0.0.5.tar.gz#md5=1ef268b40c11bf966f7c6c5504299e3e (from https://pypi.python.org/simple/xhtml2pdf/), version: 0.0.5
    Found link https://pypi.python.org/packages/source/x/xhtml2pdf/xhtml2pdf-0.0.4.tar.gz#md5=36b015a4e2918460711cbc5eebe026ce (from https://pypi.python.org/simple/xhtml2pdf/), version: 0.0.4
  Analyzing links from page https://codeload.github.com/chrisglass/xhtml2pdf/legacy.zip/28d12fcaafc4c47b13f1f6f42c2bfb73f90cc947
  Could not parse version from link: https://github.com/chrisglass/xhtml2pdf/zipball/28d12fcaafc4c47b13f1f6f42c2bfb73f90cc947#egg=xhtml2pdf  // 1
  Skipping link https://github.com/chrisglass/xhtml2pdf/zipball/28d12fcaafc4c47b13f1f6f42c2bfb73f90cc947#egg=xhtml2pdf; wrong project name (not xhtml2pdf)  // 2
  Using version 0.0.5 (newest of versions: 0.0.5, 0.0.5, 0.0.4, 0.0.4, 0.0.3, 0.0.3, 0.0.2, 0.0.2, 0.0.1, 0.0.1)
  Downloading xhtml2pdf-0.0.5.zip (118kB): 
  Downloading from URL https://pypi.python.org/packages/source/x/xhtml2pdf/xhtml2pdf-0.0.5.zip#md5=8db99aae8536436a2b7b0b3987197b99 (from https://pypi.python.org/simple/xhtml2pdf/)
...Downloading xhtml2pdf-0.0.5.zip (118kB): 118kB downloaded

如果我将版本号添加到install_requiresdependency_links的软件包(xhtml2pdf-0.0.5)中,它会找到Git链接,并且不会抱怨它们,但仍会从PyPi安装.

If I add the version number to the package (xhtml2pdf-0.0.5) in both install_requires and dependency_links it finds the Git links and doesn't complain about them, but still installs from PyPi.

我已经在寻找答案已有一段时间了,但是却找不到解决方法.我需要Git版本,因为它已经修复了PyPi版本还没有的问题.

I've been searching for an answer for a while now, but haven't been able to find the solution. I need the Git version, because it has fixes that the PyPi version doesn't have yet.

推荐答案

好,所以我解决了(或被黑客入侵,具体取决于您的看法).

Ok, so I solved (or hacked, depending on how you look at it) my own question.

代码有两个问题.

第一个问题是链接不正确.尽管我已经在其他地方看到过这种格式的文件,但是它对我来说不起作用(无论是使用setuptools mkvirtualenv mypackage还是分发mkvirtualenv --distribute mypackage).我发现它最后需要zip扩展,并在Github上找到了可以使用https://github.com/user/project/archive/commit.zip格式下载特定提交的文件.

The first issue was that the link was incorrect. Although I've seen it formatted like this elsewhere, it wouldn't work for me (whether using setuptools mkvirtualenv mypackage or distribute mkvirtualenv --distribute mypackage). I figured it needed the zip extension at the end and found out on Github you can download a specific commit using the https://github.com/user/project/archive/commit.zip format.

然后,我仍然遇到一个问题,尽管它现在可以识别链接了,但它仍然会选择Github版本中的PyPi版本.原因是,Github上的最后一次提交(在发布到PyPi之后)仍具有与PyPi上的最新版本相同的版本号.因此事实证明,这个问题实际上是

Then I still had the problem that, although it would now recognise the link, it would still pick the PyPi version over the Github version. The reason for this is that the last commits (after the release to PyPi) on Github still have the same version number as the latest version on PyPi. So it turns out this question is actually a duplicate of How can I make setuptools install a package from another source that's also available on pypi with the same version number?. To try to solve it I tried the following settings in my setup.py (some of these have been mentioned in other Stackoverflow questions as working):

install_requires=[],
dependency_links=['https://github.com/chrisglass/xhtml2pdf/archive/28d12fcaafc4c47b13f1f6f42c2bfb73f90cc947.zip',],

这根本没有安装xhtml2pdf.

This didn't install xhtml2pdf at all.

install_requires=['xhtml2pdf',],
dependency_links=['https://github.com/chrisglass/xhtml2pdf/archive/28d12fcaafc4c47b13f1f6f42c2bfb73f90cc947.zip#egg=xhtml2pdf',],

这安装了最新的PyPi版本(0.0.5).

This installed the latest PyPi version (0.0.5).

install_requires=['xhtml2pdf==0.0.5',],
dependency_links=['https://github.com/chrisglass/xhtml2pdf/archive/28d12fcaafc4c47b13f1f6f42c2bfb73f90cc947.zip#egg=xhtml2pdf-0.0.5',],

这在PyPi中安装了0.0.5版本. 实际上,如果版本号相同,则setuptools和distribution会选择Github版本上的PyPi版本,因为PyPi版本应该更稳定.

This installed the 0.0.5 version in PyPi. It actually makes sense that setuptools and distribute would choose the PyPi version over the Github version if the version number is the same, because the PyPi version should be more stable.

install_requires=['xhtml2pdf==0.0.6',],
dependency_links=['https://github.com/chrisglass/xhtml2pdf/archive/28d12fcaafc4c47b13f1f6f42c2bfb73f90cc947.zip#egg=xhtml2pdf-0.0.6',],

这是从Github下载的软件包(因为PyPi上不存在版本0.0.6),但是在安装时却抱怨版本不匹配,因为软件包中指定的版本实际上是0.0.5.

This downloaded the package from Github (because version 0.0.6 doesn't exist on PyPi), however come install time it complained that the versions didn't match, because the version specified in the package is actually 0.0.5.

install_requires=['xhtml2pdf<=0.0.6',],
dependency_links=['https://github.com/chrisglass/xhtml2pdf/archive/28d12fcaafc4c47b13f1f6f42c2bfb73f90cc947.zip#egg=xhtml2pdf-0.0.6',],

这终于奏效了. Setuptools(和发行版)意识到Github版本必须是较新的,因为这就是我所说的.在安装时,它并没有抱怨实际版本为0.0.5,因为它仍然可以满足要求.

This finally worked. Setuptools (and distribute) realised that the Github version must be newer since that's what I told it. And come install time it didn't complain about the fact that the actual version is 0.0.5 because it still meets the requirements.

您可能认为这有点骇人听闻.我对这种解决方案并不完全满意.但是我也有一个截止日期,并且有效.请注意:在实际发布0.0.6版本时,我将开始遇到问题.我想正确固定我的依赖关系,因此将来在我重新安装时不会遇到任何问题,这不是正确的固定方法.但是我想您可以使用此文档来弄乱版本号: https://pythonhosted.org/setuptools/setuptools.html#specifying -your-project-s-version . 关键是该版本应(假装)高于0.0.5,但也应是一个数字(带有可选字符),您将来不会期望在PyPi中将其显示为该版本(并且明显低于该版本).下一个发行版号很可能是(对于我来说是0.0.6).

You may consider this a bit of a hack. I'm not entirely happy with this solution. But I also have a deadline and it works. A word of caution: I will start having issues when version 0.0.6 is actually released. I want to properly pin my dependencies, so I don't run into issues in the future when I'm reinstalling, and this is not a proper pin. However I suppose you could fiddle around with the version number using this documentation: https://pythonhosted.org/setuptools/setuptools.html#specifying-your-project-s-version. Key is that the version should (pretend to) be higher than 0.0.5, but also a number (with optional characters) that you won't expect to show up as a release in PyPi in the future (and obviously lower than what the next release number will most likely be (0.0.6 in my case)).

我希望这对其他人有帮助:).

I hope this was helpful to anyone else :).

注意:我使用一个requirements.txt文件,该文件由setup.py文件进行处理以提取需求.当您在requirements.txt文件中使用https://github.com/chrisglass/xhtml2pdf/archive/28d12fcaafc4c47b13f1f6f42c2bfb73f90cc947.zip#egg=xhtml2pdf-0.0.6时,仍然可以使用pip install -r requirements.txt正常安装.

Note: I use a requirements.txt file which gets processed by the setup.py file to extract the requirements. When you use https://github.com/chrisglass/xhtml2pdf/archive/28d12fcaafc4c47b13f1f6f42c2bfb73f90cc947.zip#egg=xhtml2pdf-0.0.6 in your requirements.txt file it will also still install fine using pip install -r requirements.txt.

这篇关于Setuptools无法使用dependency_links中的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆