Home > Software engineering >  Import functions from one ipynb file to another in vs code
Import functions from one ipynb file to another in vs code

Time:12-01

I was trying to import functions from one notebook file to another in the most simplest way:

enter image description here

As you can see the files are in the same folder but I still get this error. Does anybody know how to resolve this?

CodePudding user response:

You might try using the %run magic command.

You could store your functions in a sort of library notebook and use the following line to import them in your current notebook:

%run ./func_library_notebook.ipynb

CodePudding user response:

For example, import funb() located in b.ipynb in a.ipynb.

  1. install module: pip install ipynb

  2. in a.ipynb:

     import ipynb
     from ipynb.fs.full.b import funb         // ipynb.fs.full.<notebook_name>
     funb()
    

See result:

enter image description here

  • Related