Building Cython code

Building Cython code

Using the Jupyter notebook

Cython can be used conveniently and interactively from a web browser through the Jupyter notebook. To install Jupyter notebook, e.g. into a virtualenv, use pip:

(venv)$ pip install jupyter
(venv)$ jupyter notebook

To enable support for Cython compilation, install Cython as described in the installation guide and load the Cython extension from within the Jupyter notebook:

%load_ext Cython

Then, prefix a cell with the %%cython marker to compile it:

%%cython

cdef int a = 0
for i in range(10):
    a += i
print(a)

You can show Cython’s code analysis by passing the --annotate option:

%%cython --annotate
...

 

posted @ 2020-11-08 15:51  ChuckLu  阅读(129)  评论(0)    收藏  举报