How to write setup.py to include a git repo as a dependency

前端 未结 6 1955
感情败类
感情败类 2020-12-02 10:16

I am trying to write setup.py for my package. My package needs to specify a dependency on another git repo.

This is what I have so far:



        
6条回答
  •  萌比男神i
    2020-12-02 10:42

    The following answer is deprecated for Pip 19+


    Unfortunately the other answer does not work with private repositories, which is one of the most common use cases for this. I eventually did get it working with a setup.py file that looks like this:

    from setuptools import setup, find_packages
    
    setup(
        name = 'MyProject',
        version = '0.1.0',
        url = '',
        description = '',
        packages = find_packages(),
        install_requires = [
            # Github Private Repository - needs entry in `dependency_links`
            'ExampleRepo'
        ],
    
        dependency_links=[
            # Make sure to include the `#egg` portion so the `install_requires` recognizes the package
            'git+ssh://git@github.com/example_organization/ExampleRepo.git#egg=ExampleRepo-0.1'
        ]
    )
    

    Newer versions of pip make this even easier by removing the need to use "dependency_links"-

    from setuptools import setup, find_packages
    
    setup(
        name = 'MyProject',
        version = '0.1.0',
        url = '',
        description = '',
        packages = find_packages(),
        install_requires = [
            # Github Private Repository
            'ExampleRepo @ git+ssh://git@github.com/example_organization/ExampleRepo.git#egg=ExampleRepo-0.1'
        ]
    )
    

提交回复
热议问题