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?

Ícaro
  • 1,432
  • 3
  • 18
  • 36
  • Try with link that git download generates. I guess that would work. – Irshad Bhat Mar 13 '17 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... – Ícaro Mar 13 '17 at 18:10
  • Which version of pip are you running? The newer versions require that you use the --process-dependency-links flag when installing. – nir0s Mar 13 '17 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... – Ícaro Mar 13 '17 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. – nir0s Mar 13 '17 at 18:18
  • @nir0s I'm running `pip 9.0.1`, and by adding the `VERSION` I managed to download from the repository! Thank you very much. – Ícaro Mar 13 '17 at 18:41
  • I'll post the answer. – nir0s Mar 13 '17 at 18:42

1 Answers1

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.

nir0s
  • 1,151
  • 7
  • 17
  • 1
    How do I setup a `requirements.txt` file for my module for it to be installed along with the module itself? – Ícaro Mar 13 '17 at 18:54
  • 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. – nir0s Mar 13 '17 at 19:00
  • 3
    Where can I find the answer to that other question? – foxyblue Oct 25 '17 at 15:15