2

我正在尝试为我的使用 numpy 的小模块制作 setup.py。要编译这个模块,我需要位于同一目录中的额外库

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

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

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

这行不通。

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'])
        config.add_library('libresample',['libresample.a'])
        return config

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

谢谢!

4

2 回答 2

1

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

pyzmq对此进行了某种尝试,但这并不是微不足道的: https ://github.com/zeromq/pyzmq/blob/master/setup.py

于 2013-09-09T18:38:36.220 回答
0

我发现最简单的方法是使用 os.system。但这对我来说并不好。

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
        )
于 2013-09-09T20:14:58.417 回答