user697911
user697911

Reputation: 10531

why doesn't my Cython installation import?

I want to use Cython, and did the following:

$ pip install Cython
    Requirement already satisfied: Cython in /anaconda3/envs/learn/lib/python3.6/site-packages (0.27.3)

But then it gives this error:

In [1]: cimport numpy as np                                                                                                    
  File "<ipython-input-1-9e1f0d02d1fa>", line 1
    cimport numpy as np
                ^
SyntaxError: invalid syntax


In [2]: 

After installing, what else needs to be done to use it?

Upvotes: 0

Views: 998

Answers (1)

jwalton
jwalton

Reputation: 5686

If you're trying to work in ipython or a jupyter enviornment (which it looks like you are) you'll first need to load the Cython extension : %load_ext Cython.

You then need to use %%cython to define a magic cell in which you can call your cython code:

%%cython

import numpy as np
cimport numpy as np

Upvotes: 2

Related Questions