代码之家  ›  专栏  ›  技术社区  ›  cflewis

安装时setup.py中不能指定Pip安装依赖项吗?

  •  21
  • cflewis  · 技术社区  · 15 年前

    我希望pip在用户发出安装原始软件的命令时,也从GitHub的源代码安装对GitHub的依赖关系。这两个包都不在PyPi上(而且永远不会在PyPi上)。

    pip -e git+https://github.com/Lewisham/cvsanaly@develop#egg=cvsanaly
    

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

    -e git+https://github.com/Lewisham/repositoryhandler#egg=repositoryhandler
    

    我想要的是 单一命令 用户可以发布安装原始包,让pip找到需求文件,然后安装依赖项。

    3 回复  |  直到 9 年前
        1
  •  36
  •   Community Mohan Dere    9 年前

    This answer 帮我解决了你说的那个问题。

    我有这个requirements.txt:

    PIL
    -e git://github.com/gabrielgrant/django-ckeditor.git#egg=django-ckeditor
    

    但是在安装requirements.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',
        ]
    )
    

    编辑:

    This answer

    需要将版本指定为“#egg=…”的一部分,才能标识链接中可用的包版本。 dev 在install_requires中,dependency_链接和另一个包的setup.py

    编辑: 使用 根据下面的评论,这个版本不是个好主意。

        2
  •  13
  •   Simon Charette    14 年前

    这是我用来生成的一个小脚本 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)
    
        3
  •  1
  •   daigorocub    14 年前

    setup(name='application-xpto',
      version='1.0',
      author='me,me,me',
      author_email='xpto@mail.com',
      packages=find_packages(),
      include_package_data=True,
      description='web app',
      install_requires=open('app/requirements.txt').readlines(),
      )