Import error when trying to import a ipynb file from the same directory

I created a .ipynb file myfile1.ipynb and I want to import it in another .ipynb file myfile2.ipynb, both files exist in the same directory. In order to do this, I added this line to myfile2.ipynb:

import myfile1.ipynb

However, I got the following error:

No module named myfile1

I don't understand what the problem is.

Thanks for your replies.

1 answer

  • answered 2020-01-22 00:03 Thomas

    Importing from a notebook isn't really great. When I say isn't really great, I mean that there's a little overhead you're going to have to get through. This is been discussed at length on Stack Overflow, and I'll like it here so I don't re-invent the wheel. Read the comments on the question for links to other questions asking the same thing.

    Please note that if you were importing the code from a python file in the same directory, you'd need to add a blank file to the directory to let Python know that it's okay to import from files in that directory.