Search code examples
githubsetuptoolspackagingpypitwine

PyPI install_requires direct links


I have a Python library (https://github.com/jcrozum/PyStableMotifs) that I want to publish on PyPI. It depends on another library (https://github.com/hklarner/PyBoolNet) that I do not control and that is only available on GitHub, and in particular, it is not available on PyPI. My setup.py looks like this:

from setuptools import
setup(
    ... <other metadata> ...,
    install_requires=[
    'PyBoolNet @ git+https://github.com/hklarner/[email protected]',
    ... <other packages> ...
    ]
)

Running pip install git+https://github.com/jcrozum/PyStableMotifs works perfectly, but I can't upload this to PyPI because of the following error from twine:

Invalid value for requires_dist. Error: Can't have direct dependency: 'PyBoolNet @ git+https://github.com/hklarner/[email protected]'

My understanding is that direct links are forbidden by PyPI for security reasons. Nonetheless, PyBoolNet is a hard requirement for PyStableMotifs. What do I do? Give up on PyPI?

I just want pip install PyStableMotifs to work for my users. Ideally, this command should install the dependencies and I should not have to maintain two versions of setup.py.

Failing that, I have considered creating a "dummy" package on PyPI directing users to install using the command pip install git+https://github.com/jcrozum/PyStableMotifs. Is this a bad idea (or even possible)?

Are there already established best practices for this situation or other common workarounds?

EDIT: For now, I have a clunky and totally unsatisfying workaround. I'm keeping two versions; a GitHub version that works perfectly, and a PyPI version that has the PyBoolNet requirement removed. If the user tries to import PyStableMotifs without PyBoolNet installed, an error message is shown that has install instructions for PyBoolNet. This is far from ideal in my mind, but it will have to do until I can find a better solution or until PyPI fixes this bug (or removes this feature, depending on who you ask).


Solution

  • My recommendation would be to get rid of the direct URL in install_requires, and tell your users where they can find that dependency PyBoolNet since it is not on PyPI. Don't force them on a specific installation method, but show them an example.

    Maybe simply tell your users something like:

    This project depends on PyBoolNet, which is not available on PyPI. One place where you can find it is at: https://github.com/hklarner/PyBoolNet.

    One way to install PyStableMotifs as well as its dependency PyBoolNet is to run the following command:

    python -m pip install 'git+https://github.com/hklarner/[email protected]#egg=PyBoolNet' PyStableMotifs
    

    You could additionnally prepare a requirements.txt file and tell your users:

    Install with the following command:

    python -m pip install --requirement https://raw.githubusercontent.com/jcrozum/PyStableMotifs/master/requirements.txt
    

    The content of requirements.txt could be something like:

    git+https://github.com/hklarner/[email protected]#egg=PyBoolNet
    PyStableMotifs
    

    But in the end, you should really let your users choose how to install that dependency. Your project only need to declare that it depends on that library but not how to install it.