尽管格式正确,Pip 还是忽略了 setup.py 中的 dependency_links

Pip ignores dependency_links in setup.py despite proper format

寻找过去的解决方案,例如 pip ignores dependency_links in setup.py,此配置应该有效。

我的相关内容setup.py

packages=find_packages(),
dependency_links=['http://github.com/koji-project/koji/tarball/master#egg=koji'],
install_requires=['jira', 'PyYAML', 'requests', 'psycopg2',
                  'elasticsearch', 'beanbag', 'pyzabbix', 'enum34',
                  'beautifulsoup4', 'pytz', 'koji'],
tests_require=['flake8', 'autopep8', 'mock'],
include_package_data=True,
cmdclass={'test': setupTestRequirements}

我唯一能想到的就是我的url是无效的。我不明白为什么会这样,因为它是 1.14.0 版本。

运行 pip install . 我明白了。

Could not find a version that satisfies the requirement koji (from MARs==0.17.10) (from versions: ) No matching distribution found for koji (from MARs==0.17.10)

在 运行 python setup.py develop --user 时,输出没有提到 Koji

您的配置是正确的。然而,问题出在别处。查看 koji repo on github:该项目没有 setup.py 提交。只要没有 setup.py 脚本,pipsetuptools(通过 setup.py install/setup.py develop)都无法安装您的项目,因为他们赢了'无法安装 koji 依赖项,因为它根本不是有效的 python 包。

更新:

github 上的 koji 回购的问题在于它只是位于 Fedora Pagure 上的实际开发回购的镜像,并且不与上游同步。所以正确的答案是使用真正的开发库而不是 github 镜像:

dependency_links=['git+https://pagure.io/koji.git#egg=koji-1.14.0']

简单易行。 :-)

原始答案(已过时,仅当您想从 Github 上的 kojis 存储库镜像安装时):

我看到有两种方法可以摆脱这种情况:

分叉

  1. 在 github
  2. 上分叉 koji
  3. 编写您自己的 setup.py 脚本或将其复制到某处(有关更多信息,请参见下文),提交并推送
  4. 在您项目的 setup.py.
  5. 中调整 dependency_links 中的 URL

为了测试,我准备了一个fork of koji with a setup script;如果我使用它的 URL 而不是上游仓库,安装就会成功。我还用 koji-1.14.0.post1 标记了我自己的 "release" 以将带有安装脚本的版本与普通版本区分开来。具有新依赖项的示例 setup.py

from setuptools import setup, find_packages

setup(
    name='spam',
    version='0.1',
    author='nobody',
    author_email='nobody@nowhere.com',
    url='www.example.com',
    packages=[],
    dependency_links=['https://github.com/hoefling/koji/tarball/master#egg=koji-1.14.0.post1'],
    install_requires=['koji==1.14.0.post1'],
)

使用 pip 测试安装结果:

$ pip install . --process-dependency-links
Obtaining file:///home/hoefling/python/spam
  DEPRECATION: Dependency Links processing has been deprecated and will be removed in a future release.
Collecting koji==1.14.0.post1 (from spam==0.1)
  Downloading https://github.com/hoefling/koji/tarball/master (1.4MB)
    100% |████████████████████████████████| 1.4MB 759kB/s 
Collecting pyOpenSSL (from koji==1.14.0.post1->spam==0.1)
  Using cached pyOpenSSL-17.5.0-py2.py3-none-any.whl
Collecting pycurl (from koji==1.14.0.post1->spam==0.1)
  Using cached pycurl-7.43.0.1.tar.gz
...
Installing collected packages: six, idna, asn1crypto, pycparser, cffi, 
cryptography, pyOpenSSL, pycurl, python-dateutil, chardet, certifi, 
urllib3, requests, pykerberos, requests-kerberos, rpm-py-installer, 
koji, spam
  Running setup.py install for rpm-py-installer ... done
  Running setup.py install for koji ... done
  Running setup.py install for spam ... done
Successfully installed asn1crypto-0.23.0 certifi-2017.11.5 cffi-1.11.2 
chardet-3.0.4 cryptography-2.1.4 idna-2.6 koji-1.14.0.post1 pyOpenSSL-17.5.0 
pycparser-2.18 pycurl-7.43.0.1 pykerberos-1.1.14 python-dateutil-2.6.1 
requests-2.18.4 requests-kerberos-0.11.0 rpm-py-installer-0.5.0 six-1.11.0 
spam-0.1 urllib3-1.22

安装的包看起来不错:

$ pip list
Package           Version     
----------------- ------------
asn1crypto        0.23.0      
certifi           2017.11.5   
cffi              1.11.2      
chardet           3.0.4       
cryptography      2.1.4       
idna              2.6         
koji              1.14.0.post1
pip               9.0.1       
pycparser         2.18        
pycurl            7.43.0.1    
pykerberos        1.1.14      
pyOpenSSL         17.5.0      
python-dateutil   2.6.1       
requests          2.18.4      
requests-kerberos 0.11.0      
rpm-py-installer  0.5.0       
rpm-python        4.11.3      
setuptools        38.2.4      
six               1.11.0      
spam              0.1         
urllib3           1.22        
wheel             0.30.0

此方法的缺点是在将安装脚本合并到上游之前维护分叉会产生额外的开销。这包括每次要同步上游更新时测试并最终在您的分支中调整 kojisetup.py。我可能会创建一个单独的分支,其中提交了设置脚本,sync the fork as usual,然后将分支重新定位到 fork 的 master 之上,但是如果您习惯了另一种更新策略,请坚持下去。

使用来自 TestPyPI

koji

实际上,我在 TestPyPI 上找到了一些 koji 最新版本的轮子。这也是我为上面的分支获得 setup.py 的地方 - 我下载了源代码 tar,解压缩并复制了安装脚本。这意味着 koji 开发人员正在考虑通过 PyPI 分发项目并正在处理安装脚本,但尚未提交。当他们正在处理它时,您可以使用测试包索引作为解决方法。这样,您就不会从源代码构建包,而是由 koji 开发人员构建和上传:

setup(
    ...
    dependency_links=['https://testpypi.python.org/pypi/koji'],
    install_requires=['koji'],
)

这种方法的缺点是:

  1. 您根本不知道来自 TestPyPI 的 koji 包是否可以安装。即使是这样,也不能保证安装的代码会按预期工作(尽管它应该)。当你有 fork 时,你总是可以自己修复安装脚本 - 如果 wheel 文件有错误,你就完蛋了。
  2. TestPyPI 上的包会定期删除。 From the docs:

    Note: The database for TestPyPI may be periodically pruned, so it is not unusual for user accounts to be deleted.

最后一个音符

您当然可以结合这两种解决方法,并在 dependency_links:

中同时使用 URL
setup(
    ...
    dependency_links=[
        'https://testpypi.python.org/pypi/koji',
        'https://github.com/hoefling/tarball/master#egg=koji-1.14.0.post1',
    ],
    install_requires=['koji'],
)

这样,如果在 TestPyPI 上找不到包,它将从您的分支中构建。

最后一个音符 2

您可能需要安装一些额外的系统包;至少对于我的系统 CentOS Linux release 7.3.1611 (Core) 我必须安装 curl-devel 才能满足 pycurl.