$cat say.py
print('Hello World!')
$python --version
Python 2.7.11+
$python say.py
Hello World!
$cython --version
Cython version 0.23.4
$cython say.py
$gcc `pkg-config --cflags --libs python` -o say say.c -lpython2.7 -lpthread -lm -lutil -ldl -fPIC -shared
$./say
Segmentation fault (core dumped)
答案 0 :(得分:1)
gcc
编译一个模块,可以通过python导入:
% cython say.py
% gcc `pkg-config --cflags --libs python` -o say.so say.c -lpython2.7 -lpthread -lm -lutil -ldl -fPIC -shared
% /bin/rm say.py # make sure we aren't just importing say.py
% ls -l say*
-rwxrwxr-x 1 unutbu unutbu 19693 Apr 8 07:52 say.so
-rw-rw-r-- 1 unutbu unutbu 68614 Apr 8 07:52 say.c
% python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import say
Hello World!
>>>
另请参阅"Building Cython Code"了解构建Cython代码的其他更好方法。