简体   繁体   English

Python打包:将库作为依赖项

[英]Python packaging: Boost library as dependency

Assume that someone wants to package a Python (Cython) library that depends on the C++ boost library. 假设有人想要打包依赖于C ++ boost库的Python(Cython)库。

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 (ie, apt-get install libboost-dev in Ubuntu, etc in other OSes)? 配置setup.py的最佳方法是什么,以便用户正确地告知需要安装boost库(即Ubuntu中的apt-get install libboost-dev等在其他操作系统中)? Or is it a better practice to include the boost library in the python package distribution? 或者在python包发行版中包含boost库是一种更好的做法?

The question is better asked as 问题更好

What is the best way to distribute a Python extension including an external library dependency. 分发Python扩展的最佳方法是什么,包括外部库依赖。

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. 用户不需要了解setup.py ,它用于构建和安装源代码。 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. 所以setup.py不需要任何关于这一点的任何特殊内容,它只需要知道在哪里找到标题,如果包含库以及要链接的库,它将成为项目中的子目录。

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). 文档应包括如何从源代码构建的说明,不仅需要boost(python头文件,适当的编译器等)。

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. auditwheel这样的工具会将外部库依赖项捆绑到二进制轮中,因此最终用户无需安装库即可使用您的软件包。

See also manylinux for distributing binary Python extensions and this demo project . 另请参阅manylinux以分发二进制Python扩展和此演示项目

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM