生成包含*.pyd文件的wheel
编写c文件
首先要编写c文件。此步骤略过
编写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是模块名称,source是c源码。最主要是要包括ext_modules=[Extension(MOD,sources=source)]。这是编译c文件的。
编译过程比较简单:
python setup.py bdist_wheel
如果没有pyd文件,此命令也会自动编译。
打包的wheel文件在bdist目录下。只需使用pip install [wheel文件]即可安装。
遇到的问题
如果不是最新的pip,可能会打包成功,但是pyd中的函数无法使用。建议升级pip。