如何将库编译添加到numpy.distutils.core?

2024-06-16 11:19:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我在试着设置.py对于我的小模块,它使用了numpy。为了编译这个模块,我需要额外的库,它位于同一目录中

ls -l audiotools 
total 20
-rw-rw-r-- 1 rth rth 4405 Sep  9 10:58 audiotools.c
drwxr-xr-x 6 rth rth 4096 Sep  9 11:13 libresample-0.1.3
-rw-rw-r-- 1 rth rth  741 Sep  9 11:56 setup.py

所以我需要补充一些东西设置.py它将在libresample-0.1.3中调用configure和make,然后将“libresample.a”添加到链接器命令中。在

我试过使用add_库,但它只需要源文件,而不需要整个源目录。我怎么做?在

这不管用。在

^{pr2}$

谢谢!在


Tags: 模块pynumpy目录configuresetuplssep
2条回答

据我所知,这很麻烦。通常的方法是基本上要求将lib作为共享lib安装在系统上。在

对此,pyzmq做了一些尝试,但这并非小事: https://github.com/zeromq/pyzmq/blob/master/setup.py

我发现最简单的方法就是使用操作系统. 但我觉得不太好。在

def configuration(parent_package='', top_path=None):
        import numpy
        from numpy.distutils.misc_util import Configuration

        config = Configuration('audiotools',parent_package,top_path)
        config.add_extension('audiotools', ['audiotools.c'],
                extra_link_args=[os.getcwd()+'/libresample-0.1.3/libresample.a'], 
                depends=['libresample-0.1.3/libresample.a'],

        return config

if __name__ == "__main__":
        import os
        os.system('pushd libresample-0.1.3 && ./configure CFLAGS=-fPIC && make &&popd')
        from numpy.distutils.core import setup
        setup(
                name = "audiotools",
                version='0.01',
                description='Python wrapper for GNU libresample-0.1.3 and reader Wave 24 files',
                author='Ruben Tikidji-Hamburyan, Timur Pinin',
                author_email='rth@nisms.krinc.ru, timpin@rambler.ru',
                configuration=configuration
        )

相关问题 更多 >