2

I'm trying to use Cython in a Jupyter Notebook but keep encountering an error along the lines of ImportError: dynamic module does not define module export function (PyInit__cython_magic_82a8b66e5f67c5dfa3ef71998eb9b501) (full error message at the end).

Is there something I can configure in Jupyter, Cython, Python, or elsewhere that might get Cython working for me here?

My notebook looks like:

%load_ext Cython
%%cython
cpdef int a = 0
for i in range(10):
    a += i
print(a)

I'm running Python 3.6.8, Cython 0.29.21 and Jupyter Notebook 5.7.8 from an Anaconda install, on a Windows 10 (64 bit) computer.

To install Cython I followed the instructions here: 1. install Cython to my environment with conda intall cython; 2. install Visual Studio Build Tools with the specified components; 3. copy rc.exe and rcdll.dll to C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin. I've previously had Cython working on another computer following the same instructions.

Changing the code below the %%cython magic changes the string at the end of the error message (e.g. changing to a=1 produces (PyInit__cython_magic_0be2696ff7de958048f532034feee7fd)), but nothing else.

I've tried searching for other questions with the same error, but most results are for ImportError: dynamic module does not define init function. This question (and these other questions 1, 2) has a similar module export function issue as me, but isn't using Jupyter, so I'm not sure how to translate the solution to my situation (if it even is the same issue).

Full error message:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-9-5e6525b05fe4> in <module>
----> 1 get_ipython().run_cell_magic('cython', '', 'cpdef int a = 0\nfor i in range(10):\n    a += i\nprint(a)\n')

C:\Anaconda\envs\stable\lib\site-packages\IPython\core\interactiveshell.py in run_cell_magic(self, magic_name, line, cell)
   2360             with self.builtin_trap:
   2361                 args = (magic_arg_s, cell)
-> 2362                 result = fn(*args, **kwargs)
   2363             return result
   2364 

<decorator-gen-129> in cython(self, line, cell)

C:\Anaconda\envs\stable\lib\site-packages\IPython\core\magic.py in <lambda>(f, *a, **k)
    185     # but it's overkill for just that one bit of state.
    186     def magic_deco(arg):
--> 187         call = lambda f, *a, **k: f(*a, **k)
    188 
    189         if callable(arg):

C:\Anaconda\envs\stable\lib\site-packages\Cython\Build\IpythonMagic.py in cython(self, line, cell)
    349             return None
    350 
--> 351         module = imp.load_dynamic(module_name, module_path)
    352         self._import_all(module)
    353 

C:\Anaconda\envs\stable\lib\imp.py in load_dynamic(name, path, file)
    341         spec = importlib.machinery.ModuleSpec(
    342             name=name, loader=loader, origin=path)
--> 343         return _load(spec)
    344 
    345 else:

C:\Anaconda\envs\stable\lib\importlib\_bootstrap.py in _load(spec)

C:\Anaconda\envs\stable\lib\importlib\_bootstrap.py in _load_unlocked(spec)

C:\Anaconda\envs\stable\lib\importlib\_bootstrap.py in module_from_spec(spec)

C:\Anaconda\envs\stable\lib\importlib\_bootstrap_external.py in create_module(self, spec)

C:\Anaconda\envs\stable\lib\importlib\_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

ImportError: dynamic module does not define module export function (PyInit__cython_magic_82a8b66e5f67c5dfa3ef71998eb9b501)
caaag
  • 21
  • 1

0 Answers0