Search code examples
pythonpython-3.xsetuptoolssetup.pypython-packaging

How to specify external system dependencies to a Python package?


When writing a Python package, I know how to specify other required Python packages in the setup.py file thanks to the field install_requires from setuptools.setup.

However, I do not know how to specify external system dependencies that are NOT Python packages, i.e. a commands such as git or cmake (examples) that my package could call via subprocess.call or subprocess.Popen?

Do I have to manually check the availability of the commands in my setup.py file, or is there a fancy way to specify system requirements?

Edit: I just want to be able to check if the external tools are available, and if not invite the user to install them (by themself). I do not want to manage the installation of external tools when installing the package.

Summary of contributions: it seems that setuptools has no support for this, and it would be safer to do the check at runtime (c.f. comments and answers).


Solution

  • My recommendation would be to check for the presence of those external dependencies not at install-time but at run-time. Either at the start of each run, or maybe at the first run.

    It's true that you could add this to your setup.py, but the setup.py is not always executed at install-time: for example if your project is packaged as a wheel then it doesn't even contain the setup.py file at all. And even if you do not distribute your project as a wheel, if I am not mistaken pip tends to build a wheel locally anyway and reuse it for the subsequent installations.

    So although it would be possible to do such checks as part of the setup script at install time (provided that you can guarantee the presence and execution of setup.py), I would say run-time is a safer bet.