【Cython】Cython在Windows环境下的部署安装

本文详细介绍了如何在Windows环境下安装和使用Cython。通过pip安装或下载官方压缩包进行安装,并演示了创建及编译Cython demo的过程,包括运行与测试,展示了在不同环境中可能的不同运行结果。
摘要由CSDN通过智能技术生成

1、安装

直接win+R输入cmd进入命令行,运行pip install cython(推荐)

或者安装官方Cython提供的压缩包:http://www.cython.org/#download,解压后,在解压目录运行:python setup.py install

2. 运行一个demo

创建hellocython.pyx,内容如下:

 

cdef extern from"stdio.h":
    extern int printf(const char *format, ...) 
def SayHello():
    printf("hello,world\n")
    return 0

 

代码非常简单,就是调用了C函数printf打印hello,world

 

3. 编译demo

最方便的是利用python的Distutils,先在hellocython目录下创建Setup.py:

 

from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
 
setup(
  name = 'hellocython',
  ext_modules=cythonize([
    Extension("hellocython", ["hellocython.pyx"]),
    ]),
)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值