How to build a Python C Extension so I can import it from a module

前端 未结 1 1321
时光取名叫无心
时光取名叫无心 2020-12-02 23:51

I have a Python project with many sub-modules that I package up with distutils. I would like to build some Python extensions in C to live in some of these sub-modules but I

相关标签:
1条回答
  • 2020-12-03 00:24

    Just change

    Extension('c_extension', ...)
    

    to

    Extension('foo.bar.c_extension', ...)
    

    You will need __init__.py files in each of the foo and bar directories, as usual. To have these packaged with the module in your setup.py, you need to add

    packages = ['foo', 'foo.bar'],
    

    to your setup() call, and you will need the directory structure

    setup.py
    foo/
        __init__.py
        bar/
            __init__.py
    

    in your source directory.

    0 讨论(0)
提交回复
热议问题