How to create modules in Jupyter notebook and import them? Python

MichaelRSF picture MichaelRSF · Aug 10, 2017 · Viewed 34.8k times · Source

I've created multiple python modules as .py files in a Python IDE called Pyzo in the following path: 'C:\Users\Michael\Anaconda3\Lib\site-packages' which I can then import like regular Python packages such as pandas and numpy into my Jupyter notebook or into Pyzo.

I'm a bit lost as to how to create a module in Jupyter notebook, containing a class with say a simple function, which I can then save and import into a new Jupyter notebook file.

The examples in this link below I found extremely vague and overly complicated. Any simpler examples would help, thanks! http://nbviewer.jupyter.org/github/ipython/ipython/blob/master/examples/IPython%20Kernel/Importing%20Notebooks.ipynb

Answer

ss301 picture ss301 · Mar 20, 2019
%run ./module_code.ipynb

keep this in import section- replace module_code with your file name and then you can access functions inside that file from the new notebook.