-
什么是Cython
cython 是python的超集
简单的说:python + c
-
安装
pip install Cython -U
一次性安装
pip install Cython -U--install-option="--no-cython-compile"
-
helloworld
- file: helloworld.pyx
def hello_world(name="World"): print("Hello %s!" % name)
- file: setup.py
from distutils.core import setup from Cython.Build import cythonize setup( name = 'Hello world app', ext_modules = cythonize("helloworld.pyx"), )
3. build ```language-bash python setup.py build_ext --inplace ``` 在当前目录下生成```helloworld.so``` (mac/linux, pyd windows) 4. file: main.py ```language-python from helloworld import hello_world hello_world() # out: Hello World ```
- file: helloworld.pyx
-
How
- cython 是python的超集,可以被看成是python + c
- install
- 安装
pip install Cython -U
- 一次性安装
pip install Cython -U--install-option="--no-cython-compile"
- helloworld
-
file: helloworld.pyx
def hello_world(name="World"): print("Hello %s!" % name)
-
file: setup.py
from distutils.core import setup from Cython.Build import cythonize setup( name = 'Hello world app', ext_modules = cythonize("helloworld.pyx"), )
-
build
python setup.py build_ext --inplace
在当前目录下生成
helloworld.so
(mac/linux, pyd windows) -
file: main.py
from helloworld import hello_world hello_world() # out: Hello World
-
网友评论