How to import my own Cython module to jupyter notebook

Viewed 562

The problem is I can't import my Cython module to jupyter notebook. I no clues but wonder if this has something to do with multiple conda envs I used.

Inside a cythonDir, I wrote a .pyx file with a single function defined and it was compiled successfully via a setup.py. Strangely, I can't import it to my current notebook, which is in the same directory as cythonDir. I have no problem importing the module into an interactive python terminal under parentDir though.

The overall directory tree:

- parentDir
  - notebook.ipynb
  - cythonDir

One thing to note is that my jupyter is installed in a conda env proj and the notebook is running with another kernel (environment) tf2. (the cython module is compiled under tf2).

I was doing this in order to install a single jupyter and to work with different envs via switching Kernel inside jupyter.

Thanks in advance!

2 Answers

As suggested by my friends, one can write and compile Cython code in notebook following this section.

This is not an answer, but rather an alternative method to using customed Cython module in Jupyter notebook.

Where is your setup.py ? If your package starts at parentDir, then try to follow this (it worked for me):

+ notebok.ipnb
+ parentDir
L--+ setup.py
   + python_src
   +-- script.py
   + cython_src
   L-- script.pyx

You need to be at the same level as the whole package for your notebook to be able to import it. Let me know if it works.

Related