问题
Assume that someone wants to package a Python (Cython) library that depends on the C++ boost library.
What is the best way to configure the setup.py
so that the user is properly informed that it is required to install the boost library (i.e., apt-get install libboost-dev
in Ubuntu, etc in other OSes)? Or is it a better practice to include the boost library in the python package distribution?
回答1:
The question is better asked as
What is the best way to distribute a Python extension including an external library dependency.
This is better dealt with binary wheel packages.
User does not need to know anything about setup.py
, which is used for building and installing source code. User just needs to download and install a binary wheel package.
Including just the header files does not solve the problem of needing the library to build with and link to. It also opens up issues with version incompatibilities.
So setup.py
need not have anything special about any of this, it just needs to know where to find headers which will be a sub-dir in your project if the library is included and which libraries to link with.
The documentation should include instructions on how to build from source, for which more than just boost is needed (python header files, appropriate compilers etc).
Tools like auditwheel then take care of bundling external library dependencies into the binary wheel, so end-users need not have the library installed to use your package.
See also manylinux for distributing binary Python extensions and this demo project.
来源:https://stackoverflow.com/questions/46824239/python-packaging-boost-library-as-dependency