【问题标题】:pip install dependency linkspip 安装依赖链接
【发布时间】:2014-11-21 14:03:39
【问题描述】:

我正在使用python version 2.7pip version is 1.5.6

我想从 url 安装额外的库,例如正在安装 setup.py 上的 git repo。

我在setup.pyinstall_requires 参数中添加了额外内容。这意味着,我的库需要额外的库,并且它们也必须安装。

...
install_requires=[
    "Django",
    ....
],
...

但是像 git repos 这样的 url 在install_requires 中不是setup.py 中的有效字符串。假设,我想从 github 安装一个库。我已经搜索过这个问题,我发现了一些我可以在dependency_links 中放入库的东西@ 987654329@。但这仍然行不通。这是我的依赖链接定义;

dependency_links=[
    "https://github.com/.../tarball/master/#egg=1.0.0",
    "https://github.com/.../tarball/master#egg=0.9.3",
], 

链接有效。我可以使用这些网址从互联网浏览器下载它们。我的设置仍然没有安装这些额外的库。我也试过--process-dependency-links参数来强制pip。但结果是一样的。我点的时候没有错误。

安装后,我看到pip freeze 中没有库导致dependency_links

我怎样才能通过我的setup.py 安装来下载它们?

编辑:

这是我完整的setup.py

from setuptools import setup

try:
    long_description = open('README.md').read()
except IOError:
    long_description = ''

setup(
    name='esef-sso',
    version='1.0.0.0',
    description='',
    url='https://github.com/egemsoft/esef-sso.git',
    keywords=["django", "egemsoft", "sso", "esefsso"],
    install_requires=[
        "Django",
        "webservices",
        "requests",
        "esef-auth==1.0.0.0",
        "django-simple-sso==0.9.3"
    ],
    dependency_links=[
        "https://github.com/egemsoft/esef-auth/tarball/master/#egg=1.0.0.0",
        "https://github.com/egemsoft/django-simple-sso/tarball/master#egg=0.9.3",
    ],

    packages=[
        'esef_sso_client',
        'esef_sso_client.models',
        'esef_sso_server',
        'esef_sso_server.models',
    ],
    include_package_data=True,
    zip_safe=False,
    platforms=['any'],
)

编辑 2:

这里是 pip 日志;

Downloading/unpacking esef-auth==1.0.0.0 (from esef-sso==1.0.0.0)
  Getting page https://pypi.python.org/simple/esef-auth/
  Could not fetch URL https://pypi.python.org/simple/esef-auth/: 404 Client Error: Not Found
  Will skip URL https://pypi.python.org/simple/esef-auth/ when looking for download links for esef-auth==1.0.0.0 (from esef-sso==1.0.0.0)
  Getting page https://pypi.python.org/simple/
  URLs to search for versions for esef-auth==1.0.0.0 (from esef-sso==1.0.0.0):
  * https://pypi.python.org/simple/esef-auth/1.0.0.0
  * https://pypi.python.org/simple/esef-auth/
  Getting page https://pypi.python.org/simple/esef-auth/1.0.0.0
  Could not fetch URL https://pypi.python.org/simple/esef-auth/1.0.0.0: 404 Client Error: Not Found
  Will skip URL https://pypi.python.org/simple/esef-auth/1.0.0.0 when looking for download links for esef-auth==1.0.0.0 (from esef-sso==1.0.0.0)
  Getting page https://pypi.python.org/simple/esef-auth/
  Could not fetch URL https://pypi.python.org/simple/esef-auth/: 404 Client Error: Not Found
  Will skip URL https://pypi.python.org/simple/esef-auth/ when looking for download links for esef-auth==1.0.0.0 (from esef-sso==1.0.0.0)
  Could not find any downloads that satisfy the requirement esef-auth==1.0.0.0 (from esef-sso==1.0.0.0)
Cleaning up...
  Removing temporary dir /Users/ahmetdal/.virtualenvs/esef-sso-example/build...
No distributions at all found for esef-auth==1.0.0.0 (from esef-sso==1.0.0.0)
Exception information:
Traceback (most recent call last):
  File "/Users/ahmetdal/.virtualenvs/esef-sso-example/lib/python2.7/site-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/Users/ahmetdal/.virtualenvs/esef-sso-example/lib/python2.7/site-packages/pip/commands/install.py", line 278, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/Users/ahmetdal/.virtualenvs/esef-sso-example/lib/python2.7/site-packages/pip/req.py", line 1177, in prepare_files
    url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
  File "/Users/ahmetdal/.virtualenvs/esef-sso-example/lib/python2.7/site-packages/pip/index.py", line 277, in find_requirement
    raise DistributionNotFound('No distributions at all found for %s' % req)
DistributionNotFound: No distributions at all found for esef-auth==1.0.0.0 (from esef-sso==1.0.0.0)

看来,它没有使用dependency_links 中的来源。

【问题讨论】:

    标签: python pip setuptools


    【解决方案1】:

    我遇到了类似的情况,我想将 shapely 用作我的包依赖项之一。但是,Shapely 有一个警告,如果您使用的是 Windows,则必须使用来自 http://www.lfd.uci.edu/~gohlke/pythonlibs/ 的 .whl 文件。否则,您必须安装 C 编译器,这是我不想要的。我希望用户简单地使用pip install mypackage 而不是安装一堆其他东西。

    如果你有dependency_links的典型设置

    setup(
      name = 'streettraffic',
      packages = find_packages(), # this must be the same as the name above
      version = '0.1',
      description = 'A random test lib',
      author = 'Costa Huang',
      author_email = 'Costa.Huang@outlook.com',
      install_requires=['Shapely==1.5.17'],
      dependency_links = ['http://www.lfd.uci.edu/~gohlke/pythonlibs/ru4fxw3r/Shapely-1.5.17-cp36-cp36m-win_amd64.whl']
    )
    

    然后运行pip install .,它只会在 Pypi 上选择形状,并在 Windows 安装上造成麻烦。经过几个小时的研究,我找到了这个链接Force setuptools to use dependency_links to install mysqlclient,并且基本上使用from setuptools.command.install import install as _install手动安装。

    from setuptools.command.install import install as _install
    from setuptools import setup, find_packages
    import pip
    
    class install(_install):
      def run(self):
        _install.do_egg_install(self)
    
        # just go ahead and do it
        pip.main(['install', 'http://localhost:81/Shapely-1.5.17-cp36-cp36m-win_amd64.whl'])
    
    setup(
      name = 'mypackage',
      packages = find_packages(), # this must be the same as the name above
      version = '0.1',
      description = 'A random test lib',
      author = 'Costa Huang',
      author_email = 'test@outlook.com',
      cmdclass={'install': install}
    )
    

    脚本运行良好。希望对您有所帮助。

    【讨论】:

      【解决方案2】:

      启用dependency_links--process-dependency-links 选项是removed in Pip 19.0

      相反,您可以使用PEP 508 URL 来指定您的依赖关系,即supported since Pip 18.1。这是setup.py的示例摘录:

      install_requires=[
          "numpy",
          "package1 @ git+https://github.com/user1/package1",
          "package2 @ git+https://github.com/user2/package2@branch1",
      ],
      

      请注意,Pip 不支持从 PyPI 和未来的 you will not be able to upload them to PyPI (see news entry for Pip 18.1) 安装具有此类依赖项的软件包。

      【讨论】:

      • 与dependency_links不同,这个解决方案对我有用。
      • 你仍然需要(至少在我的情况下)保持dependency_links 与python setup.py install一起安装
      • @educolo 建议将 PEP508 语法与 dependency_links 结合使用是目前使私有 repo 包在 pip installsetuptools 中工作的唯一方法(用于嵌套pip) 中的依赖项:pip 19.0 及更高版本不再支持 dependency_links,而 setuptools still prefers PyPI over PEP 508 specified URLs in install_requires
      • dependency_links 被删除的说法不正确,请点击您发布的链接并重新阅读注释。
      【解决方案3】:

      Pip 不久前移除了对dependency_links 的支持。 latest version of pip that supports dependency_links is 1.3.1,安装它

      pip install pip==1.3.1
      

      此时您的依赖链接应该可以工作。请注意,dependency_links 始终是 pip 的最后手段,即。如果 pypi 上存在同名包,它将被选择而不是你的包。

      注意,https://github.com/pypa/pip/pull/1955 似乎开始允许依赖链接,pip 保留了它,但您可能需要使用一些命令行开关来使用更新版本的 pip。

      编辑:从 pip 7 开始......他们重新考虑了 dep 链接并启用了它们,即使他们没有删除弃用通知,但它们似乎仍然存在于讨论中。使用 pip>=7 可以安装东西

      pip install -e . --process-dependency-links --allow-all-external
      

      或者将以下内容添加到 pip.conf 中,例如/etc/pip.conf

      [install]
      process-dependency-links = yes
      allow-all-external = yes
      trusted-host =
          bitbucket.org
          github.com
      

      编辑

      我学到的一个技巧是将版本号提高到非常高的水平,以确保 pip 不喜欢非依赖链接版本(如果这是你想要的)。从上面的示例中,使依赖链接看起来像:

      "https://github.com/egemsoft/django-simple-sso/tarball/master#egg=999.0.0",
      

      还要确保版本看起来像示例或者是日期版本,任何其他版本都会使 pip 认为它是开发版本并且不会安装它。

      【讨论】:

      • 看起来不再是这种情况了?据我所知,最新的 pip 支持dependency_links。
      • 您仍然会看到警告,但dependency_links 会保留一段时间。据我所知,您仍然需要配置,请参阅答案编辑部分中的注释。
      • 也许你应该删除关于 pip 版本 1.3.1 的信息,它已经很旧了
      • @thibaultketterer 答案有编辑,它仍然是正确的,因为不需要编辑它
      • 非常感谢 egg= 版本的把戏,这是拼图中缺少的部分!
      【解决方案4】:

      您需要确保在 install_requires 中也包含依赖项。

      这是一个例子setup.py

      #!/usr/bin/env python
      from setuptools import setup
      
      setup(
          name='foo',
          version='0.0.1',
          install_requires=[
              'balog==0.0.7'
          ],
          dependency_links=[
              'https://github.com/balanced/balog/tarball/master#egg=balog-0.0.7'
          ]
      )
      

      这是您的示例 setup.py 的问题:

      您在设置的依赖链接中缺少 egg 名称。

      你有

      https://github.com/egemsoft/esef-auth/tarball/master/#egg=1.0.0.0

      你需要

      https://github.com/egemsoft/esef-auth/tarball/master/#egg=esef-auth-1.0.0.0

      【讨论】:

      • 上面写着Could not find any downloads that satisfy the requirement my-extra-libraray==1.0.0.0 (from my-installed-library-currently==1.0.0.0)
      • @AhmetDAL 你有指定的依赖链接和安装要求吗?您可以发布您正在使用的完整的setup.py 吗?
      • 结果还是一样。这是我的setup.py。你可以试试pip install git+https://github.com/egemsoft/esef-sso.git。你可能会看到结果。
      • django-simple-sso 也应该来自我的分叉源。它来自原始来源。我认为,install_requires 不使用dependency_links 作为来源。
      猜你喜欢
      • 2016-08-21
      • 2018-09-27
      • 2011-01-20
      • 2019-01-10
      • 2021-05-29
      • 2018-09-04
      • 2023-04-03
      • 2020-10-04
      • 2013-11-20
      相关资源
      最近更新 更多