7

When I'm listing dependencies in a setup.py file's install_requires entry, how do I specify that in order to install a given package, a different name must be passed to pip than the package name?

For example, I can use pip to install pyinterval from PyPI, which I can then use in my code by doing from interval import interval, inf, imath or similar. Is there a way to tell SetupTools that the pyinterval entity "provides" the interval package or something?

Edit: I found the packaging glossary, which clarifies for me the terminology difference between a "distribution package" and an "import package". In my case, pyinterval is the distribution package, which provides the interval import package.

Ken Williams
  • 22,756
  • 10
  • 85
  • 147
  • Related: http://stackoverflow.com/questions/27308293/how-to-install-python-package-with-a-different-name-using-pip. Both `django-emoji` and `emoji` on PyPI provide a `emoji` package to import, just like `pyinterval` and `interval` on PyPI both provide an `interval` package to import. – Ken Williams Mar 09 '17 at 22:52

1 Answers1

0

You do not need to tell setuptools about what is the 'command' each dependency provides. You just need to install the package by it's name i.e. pyinterval. It's up to you to know which package provides which 'command', in this case the pyinterval package provides the interval 'command' that is actually an entry point (as detailed in the following paragraph).

This functionality about packages registering keys that other packages can query for and use is usually achieved through entry points, you can read more about it in the following link as an example: http://the-hitchhikers-guide-to-packaging.readthedocs.io/en/latest/creation.html#entry-points

To sum up just tell setuptools which packages your library will require, you can find a lot of examples in GitHub:

https://github.com/search?l=Python&o=asc&p=6&q=install_requires&ref=searchresults&s=indexed&type=Code&utf8=%E2%9C%93

Check for example Flask's: https://github.com/pallets/flask/blob/master/setup.py

Enrique Saez
  • 2,504
  • 16
  • 21
  • 1
    I'm not clear on what meaning of "package" you're using. In my example, is the package `pyinterval`, or `interval`? A lot of sources (e.g. http://www.learnpython.org/en/Modules_and_Packages) seem to conflate it to mean at least 2 different things: https://pypi.python.org/pypi says `pip install package`, either the object in PyPI, or a directory containing code that we can load using `import`. – Ken Williams Mar 09 '17 at 22:48
  • I updated the answer to clarify that in your case the package is `pyinterval`. `interval` is an entry point provided by the `pyinterval` package. Packages are, as detailed in the link you provided (http://www.learnpython.org/en/Modules_and_Packages), directories with a twist. What pip does to install a package is fetching a package from PyPI (a compressed directory) and executing its `setup.py`. You can read more about it here: https://pip.pypa.io/en/latest/reference/pip_install/#overview – Enrique Saez Mar 09 '17 at 23:10
  • Thanks for the clarification. Maybe part of my confusion is that in PyCharm, if I have `pyinterval` in my `install_requires` entry, and one of my code files has `from interval import interval`, it still complains that "Package 'interval' is not listed in project requirements." So I thought I was doing it wrong, but maybe it's just a bug in PyCharm, to not notice that it's already satisfied. – Ken Williams Mar 10 '17 at 16:29