Ipython中的Cython:错误:找不到单元格魔法`%%Cython`

Ipython中的Cython:错误:找不到单元格魔法`%%Cython`,ipython,cython,Ipython,Cython,在ipython笔记本中使用cython时,我看到下面的错误。怎么了 %load_ext cythonmagic /usr/local/lib/python2.7/dist-packages/IPython/extensions/cythonmagic.py:21: UserWarning: The Cython magic has been moved to the Cython package warnings.warn("""The Cython magic has been

在ipython笔记本中使用
cython
时,我看到下面的错误。怎么了

%load_ext cythonmagic
/usr/local/lib/python2.7/dist-packages/IPython/extensions/cythonmagic.py:21: UserWarning: The Cython magic has been moved to the Cython package
      warnings.warn("""The Cython magic has been moved to the Cython package""")



%%cython
def fib(int n):
    cdef int a,b,i
    for i in range(n):
        a,b=a+b,b
    return a 

ERROR: Cell magic `%%cython` not found.

警告试图传达的是,定义
%%cython
magic的扩展已移动到cython包,而不是IPython包。所以不是

%load_ext cythonmagic
你应该做:

%load_ext Cython

在此之后,cython magic将按预期工作。

记住将扩展加载到其他单元格中

如果在同一单元格中加载并使用Cython扩展,则会出错:

使用同一单元格:

使用不同的单元格:

如果使用pip安装ipython(即不使用Anaconda等分发工具),则需要先将Cython模块安装到python或virtualenv:
pip安装Cython