5

For distributing Python libraries on PyPi, I usually specify the package's dependencies in setup.py à la

setup(
    # ...
    install_requires=["numpy", "scipy"],
    # ...
)

In some cases, however, I already need to import something in the setup.py, for example when using pybind11. The recommended way for finding the pybind11 include directory is via

def __str__(self):
    import pybind11  # !
    return pybind11.get_include(self.user)

Hence, the user needs pybind11 installed before pip tries to install the library itself. Unfortunately, simply adding the module to install_requires doesn't cut it: One gets

  ModuleNotFoundError: No module named 'pybind11'

when trying to install. Is there a way to enforce installation of requirements before evaluating setup.py?

Nico Schlömer
  • 53,797
  • 27
  • 201
  • 249
  • I think that the dependencies are installed quite early on. So did you try to simply add pybind11 to the required list? If it is evaluated before finding your include path it might just work like that – Tom de Geus Jul 13 '18 at 11:24
  • If you mean `install_requires` by "required list" then yes, I did try that. Not working.(I'll clarify that in the question.) – Nico Schlömer Jul 13 '18 at 11:27
  • 1
    Take a look at this [SO Post](https://stackoverflow.com/questions/44308548/how-should-i-handle-importing-third-party-libraries-within-my-setup-py-script) – gyx-hh Jul 13 '18 at 12:29

0 Answers0