用distutils构造Cpthon模块
第一步:先写一个hello.pyx脚本
def say_hello_to(name):
print("Hello %s!" % name)
from distutils.core import setup
from Cython.Build import cythonize
setup(
name = 'Hello world app',
ext_modules = cythonize("hello.pyx"),
)
第三步:编译
python setup.py build_ext --inplace
from hello import say_hello_to
print(say_hello_to('Cpython Demo'))
Note:对于python2而言,脚本所在文件夹如果不是英文则需要修改编码方式
Link:http://cython.readthedocs.io/en/latest/src/quickstart/build.html