python setup.py build命令解析

x33g5p2x  于2022-06-10 转载在 Python  
字(0.6k)|赞(0)|评价(0)|浏览(385)

python ——setup.py build_ext --inplace命令解析

1. 用python setup.py --help-commands
首先要有个setup.py,用setuptools实现python的setup,这里是一个setup.py的例子:

from setuptools import setup
from setuptools import Extension

example_module = Extension(name='numpy_demo',  # 模块名称
                           sources=['example.cpp'],    # 源码
                           include_dirs=[r'/home/data/CM/10_device/pybind11/include']
                           )

setup(ext_modules=[example_module])

该例子是用pybind11模块,用c++给python写一个模块

2. 命令解析

  • build_ext:build C/C++ extensions (compile/link to build directory),给python编译一个c、c++的拓展
  • –inplace:ignore build-lib and put compiled extensions into the source directory alongside your pure Python modules,忽略build-lib,将编译后的扩展放到源目录中,与纯Python模块放在一起

相关文章