Generate a wheel containing *.pyd files
write c file
First, write the c file. Skip this step
write setup.py
#incoding:utf-8
from distutils.core import setup,Extension
MOD = 'marshall'
#资源(要编译和链接的代码文件)
source = ['marshall.c','marshallw.c']
setup(
name='marshall',
ext_modules=[Extension(MOD,sources=source)],
version='1.0.0',
description='c algorithm for python',
long_description='additional algorithm for python',
author='Marshall',
author_email='',
url='',
license='MIT',
python_requires='>=3',
platforms='Windows',
include_package_data=True,
)
MOD is the module name, and source is the c source code. The main thing is to include ext_modules=[Extension(MOD,sources=source)]. This is what compiles the c file.
The compilation process is relatively simple:
python setup.py bdist_wheel
This command also compiles automatically if there is no pyd file.
The packaged wheel file is in the bdist directory. Just use pip install [wheel file] to install.
problems encountered
If it is not the latest pip, it may be packaged successfully, but the functions in pyd cannot be used. It is recommended to upgrade pip.