2

I am creating a module and need to prepare my setup.py file to have some requirements. One of the requirements is a fork of one package that is already in PyPI so I want to reference my GitHub repository directly.

I tried two configurations, the first one is:

setup(
    'name': 'mymodule',
    # other arguments
    install_requires=[
        'myrequirement',  # The dependency name
    ],
    dependency_links=[
        'https://github.com/ihhcarus/myrequirement.git#egg=myrequirement',  # This is my repository location
    ]
)

I create a local distribution of my module using python setup.py sdist and when I run pip install path/to/module/dist/mymodule-0.1.tar.gz it ends up installing the version on PyPI and not my repository.

The other configuration, I tried to change the requirement name to force searching for a dependency link like so:

setup(
    'name': 'mymodule',
    # other arguments
    install_requires=[
        'myrequirement_alt',  # The dependency name with a suffix
    ],
    dependency_links=[
        'https://github.com/ihhcarus/myrequirement.git#egg=myrequirement_alt',  # This is my repository location
    ]
)

But with this, I only end up getting an error that myrequirement_alt is not found...

So I ask, what is the right way to achieve this without using PyPI?

7
  • Try with link that git download generates. I guess that would work. Commented Mar 13, 2017 at 17:43
  • @IrshadBhat If I run pip install ... directly it works for my repository but I still can't use that in the setup.py dependencies... Commented Mar 13, 2017 at 18:10
  • Which version of pip are you running? The newer versions require that you use the --process-dependency-links flag when installing. Commented Mar 13, 2017 at 18:14
  • @nir0s by using the --process-dependency-links flag I get a deprecation error: DEPRECATION: Dependency Links processing has been deprecated and will be removed in a future release.. Results seem to be the same too... Commented Mar 13, 2017 at 18:17
  • 1
    That's true. It is deprecated and should not be used. You should be using a requirements.txt file to install things from github. And what do you mean by the result is the same? It doesn't install from the link? (again, which version of pip are you using?). Also, use https://github.com/ihhcarus/myrequirement.git#egg=myrequirement_alt-VERSION instead. Version being the package version you'd like to install. Commented Mar 13, 2017 at 18:18

1 Answer 1

1

For dependency links to work you need to add the version number of the package to https://github.com/ihhcarus/myrequirement.git#egg=myrequirement_alt. or it will not know what to install.

e.g.:

setup(
    'name': 'mymodule',
    # other arguments
    install_requires=[
        'myrequirement',  # The dependency name
    ],
    dependency_links=[
        'https://github.com/ihhcarus/myrequirement.git#egg=myrequirement_alt-1.3'  # Link with version at the end
    ]
)

Note that I wouldn't recommend using dependency links at all as they're deprecated. You should probably, instead, use requirement files.

Sign up to request clarification or add additional context in comments.

3 Comments

How do I setup a requirements.txt file for my module for it to be installed along with the module itself?
You can't. Requirement files must be explicitly passed using pip's -r flag. That's another question though to be answered. Please approve the answer if it solved your problem.
Where can I find the answer to that other question?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.