Search code examples
pythonsoftware-distribution

Python scripts that depend on binaries... how to distribute?


I have a codebase that includes some C++ code and Python scripts that make use of the resulting binaries (via the subprocess module).

root/
    experiments/
        script_1.py (needs to call binary_1)
    clis/
        binary_1.cc
        binary_1

What's the best way to refer to the binary from the Python scripts?

  • A relative path from the Python script's directory to the binary, which assumes the user will be running the Python script from a particular directory
  • Just the binary name, which assumes the user will have added the binary's directory to the $PATH variable, or copied the binary to /usr/local/bin, or something
  • Something else?

Solution

  • If your binaries are pre-compiled you can use the data_files parameter to setuptools. Have it installed in /usr/local/bin.

    data_files=[("/usr/local/bin", glob("bin/*"))], ...