使用pip安装依赖的基于Github的包

时间:2016-02-08 15:54:59

标签: python git pip python-3.5

我在Github上有一个带有setup.pyrequirements.txt的Python回购。最初,setup.py包含了以下内容:

setup(
  ...
  install_requires=[x for x in open("requirements.txt").read().splitlines() if "://" not in x],
  dependency_links=[x for x in open("requirements.txt").read().splitlines() if "://" in x]
)

当我为此repo执行pip install git+https://github.com/foo/bar.git@branch#egg=foo时,它正确安装了install_requires依赖项,但忽略了dependency_links中其他基于Github的依赖项。

经过大量调查 - StackOverflow,#python和文档(FWIW) - 有一个建议是{@ 1}}已被弃用,所有内容都应放入dependency_links。所以我将install_requires更改为:

setup.py

现在pip抱怨,只要它到达基于Github的依赖 - 让我们称之为setup( ... install_requires=open("requirements.txt").read().splitlines() ) - 它期待“版本规范”。我试过了:

  • quux
  • git+https://github.com/foo/quux.git@branch#egg=quux==0.1.0
  • git+https://github.com/foo/quux.git@branch#egg=quux#version==0.1.0

...以及没有指定任何版本,在我的git+https://github.com/foo/quux.git@branch#egg=quux&version==0.1.0中有和没有前面的-e并且我一直收到此错误。我也为URL方案尝试了不同的格式,也没有任何区别。

如何格式化requirements.txtrequirements.txt以处理基于Git的依赖项?

1 个答案:

答案 0 :(得分:0)

对我有用的是使用此conf/wrapper.conf文件运行pip install --process-dependency-links ...

setup.py

请注意,正如您所说,setup( ... install_requires=[ 'my_lib==0.1.0', ], dependency_links=[ 'git+ssh://git@github.com/foo/quux.git@branch#egg=my_lib-0.1.0', ] ) 已弃用,并且将在未来的pip版本中删除。在那种情况下,我不知道解决方案是什么。