一、安装
sudo apt-get install python-dev
sudo apt install cython
二、代码
$ cat hello.pyx
print("你好Cython!")
$ cat Makefile
all:
cython -3 -o hello.c hello.pyx
gcc -g -O2 -fpic -c hello.c -o hello.o `python-config --cflags`
gcc -g -O2 -shared -o hello.so hello.o `python-config --libs`
clean:
rm hello.o hello.c hello.so
三、运行
$ make
cython -3 -o hello.c hello.pyx
gcc -g -O2 -fpic -c hello.c -o hello.o `python-config --cflags`
gcc -g -O2 -shared -o hello.so hello.o `python-config --libs`
mymotif@mymotif-ThinkPad-X240:~/prg/mypython/cpyhello$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import hello
你好Cython!
>>>