Cython in Ipython: ERROR: Cell magic `%%cython` not found

馋奶兔 提交于 2019-12-21 03:33:24

问题


While using cython in ipython notebook, I see the error below. What's wrong?

%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.

回答1:


What the warning is trying to communicate is that the extension defining the %%cython magic has moved to the Cython package, out of the IPython package. So instead of

%load_ext cythonmagic

you should do:

%load_ext Cython

After that, the cython magic should work as expected.




回答2:


Remember to load the extension in a different cell.

If you load and use the Cython extension in the same cell, you will fall in error:

Using the same cell:

Using a different cell:



来源:https://stackoverflow.com/questions/36514338/cython-in-ipython-error-cell-magic-cython-not-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!