Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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. 
like image 452
aman Avatar asked Apr 09 '16 08:04

aman


2 Answers

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.

like image 172
minrk Avatar answered Sep 18 '22 15:09

minrk


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:
Here the function does not exist

Using a different cell:
This will work

like image 32
alessiosavi Avatar answered Sep 19 '22 15:09

alessiosavi