编译pyd文件
-
安装cython
pip install cython -
编写setup.py 文件
import os
import shutil
from setuptools import setup
from Cython.Build import cythonize
filename = 'org.py'
setup(
name='xxxx',
ext_modules=cythonize(filename), # 打包文件的名称,默认与setup.py在同一路径下
)
tmp_file = filename.replace('.py', '.c')
os.remove(tmp_file)
shutil.rmtree('build')
print('finished.')
-
执行编译命令
python setup.py build_ext --inplace -
编译完成后会在同目录下出现.pyd文件.
-
编译后的pyd 文件报win32错误
安装pywin32后重新编译即可.