Pip可以在安装时安装setup.py中未指定的依赖项吗?

cfl*_*wis 21 python pip setuptools

当用户发出安装原始软件的命令时,我想在pit上安装我在GitHub上的依赖项,也可以从GitHub上的源代码安装.这些软件包都不在PyPi上(永远不会).

用户发出命令:

pip -e git+https://github.com/Lewisham/cvsanaly@develop#egg=cvsanaly
Run Code Online (Sandbox Code Playgroud)

这个repo有一个requirements.txt文件,另一个依赖于GitHub:

-e git+https://github.com/Lewisham/repositoryhandler#egg=repositoryhandler
Run Code Online (Sandbox Code Playgroud)

我想是一个命令,一个用户可以发出来安装原包,有点子找到要求的文件,然后安装依赖了.

Gab*_*ant 36

这个答案帮助我解决了你所说的同样问题.

似乎没有一种简单的方法可以让setup.py直接使用需求文件来定义它的依赖关系,但是可以将相同的信息放入setup.py本身.

我有这个要求.txt:

PIL
-e git://github.com/gabrielgrant/django-ckeditor.git#egg=django-ckeditor
Run Code Online (Sandbox Code Playgroud)

但是在安装requires.txt包含的包时,pip会忽略这些要求.

这个setup.py似乎强迫pip安装依赖项(包括我的github版本的django-ckeditor):

from setuptools import setup

setup(
    name='django-articles',
    ...,
    install_requires=[
        'PIL',
        'django-ckeditor>=0.9.3',
    ],
    dependency_links = [
        'http://github.com/gabrielgrant/django-ckeditor/tarball/master#egg=django-ckeditor-0.9.3',
    ]
)
Run Code Online (Sandbox Code Playgroud)

编辑:

这个答案还包含一些有用的信息.

将版本指定为"#egg = ..."的一部分,需要确定链接上可用的软件包版本.但请注意,如果您总是希望依赖于最新版本,则可以将版本设置为devinstall_requires,dependency_links和其他软件包的setup.py.

编辑:使用dev版本不是一个好主意,如下面的评论.

  • "dev"的技巧只能在第一次工作,而不是随后的工作.setup.py只检查"dev"字符串作为自身的版本 (3认同)
  • @DanEEStar那是对的.一旦安装了包的_dev_版本,`setuptools`就会考虑满足要求.正如[链接答案](http://stackoverflow.com/a/2163919/396967)所示,您需要同步更新*所有3个地方的包版本*:依赖项的`setup.py`和`install_requires`和`dependency_links` - 不太实际. (2认同)

Sim*_*tte 13

下面是我用来生成一个小的脚本install_requires,并dependency_links从需求文件.

import os
import re

def which(program):
    """
    Detect whether or not a program is installed.
    Thanks to http://stackoverflow.com/a/377028/70191
    """
    def is_exe(fpath):
        return os.path.exists(fpath) and os.access(fpath, os.X_OK)

    fpath, _ = os.path.split(program)
    if fpath:
        if is_exe(program):
            return program
    else:
        for path in os.environ['PATH'].split(os.pathsep):
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return exe_file

    return None

EDITABLE_REQUIREMENT = re.compile(r'^-e (?P<link>(?P<vcs>git|svn|hg|bzr).+#egg=(?P<package>.+)-(?P<version>\d(?:\.\d)*))$')

install_requires = []
dependency_links = []

for requirement in (l.strip() for l in open('requirements')):
    match = EDITABLE_REQUIREMENT.match(requirement)
    if match:
        assert which(match.group('vcs')) is not None, \
            "VCS '%(vcs)s' must be installed in order to install %(link)s" % match.groupdict()
        install_requires.append("%(package)s==%(version)s" % match.groupdict())
        dependency_links.append(match.group('link'))
    else:
        install_requires.append(requirement)
Run Code Online (Sandbox Code Playgroud)