cython 试用

周海汉 /文

2010.1.24

 

1.安装

zhouhh@zhouhh-home:~$ cython
程序“cython”尚未安装。  您可以使用以下命令安装:
sudo apt-get install cython
cython: command not found
zhouhh@zhouhh-home:~$ sudo apt-get install cython

...

2.写测试代码:

zhouhh@zhouhh-home:~$ vi test.pyx

3.编译成C语言

zhouhh@zhouhh-home:~$ cython test.pyx

zhouhh@zhouhh-home:~$ ls test.c
test.c
test.c是由cython通过 test.pyx生成的。

 

4. gcc编译成.o文件

直接执行gcc会出错,必须包含python目录。

zhouhh@zhouhh-home:~$ gcc  test.c

test.c:4:20: error: Python.h: 没有该文件或目录
test.c:5:26: error: structmember.h: 没有该文件或目录
test.c:7:6: error: #error Python headers needed to compile C extensions, please install development version of Python.

...

 

zhouhh@zhouhh-home:~$ gcc -c -fPIC -I/usr/include/python2.6 test.c

-fPIC表示编译成共享库,-I后跟include的路径。

 

5.生成共享库

zhouhh@zhouhh-home:~$ gcc -shared test.o -o test.so

 

6.在python中引用共享库

zhouhh@zhouhh-home:~$ vi test.py

import test

test.sayhello('ni hao')

 

7.执行

zhouhh@zhouhh-home:~$ python test.py
ni hao

8.疑问:

不知怎么穿NULL指针给函数参数。

 

9.参考:

http://www.cython.org/

http://blog.csdn.net/lanphaday/archive/2009/09/17/4561611.aspx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值