%run command to run .ipynb file forces .py extension

Viewed 76

I am trying to execute a simple run command:

%run /WaterfallViz.ipynb

But no matter how I format it I keep getting the same error:

ERROR:root:File `'/WaterfallViz.ipynb.py'` not found.

How do I prevent the .py extension to insert itself at the end of the file name?

2 Answers

If you have moved the notebook file where you %run another notebook, unfortunately Jupyter will still reference to the original directory path.

To fix this behavior, simply:

  • save your notebook
  • create a new notebook
  • copy the content from the original notebook
  • open the new notebook file

The %run now should work as the "directory path" is the one you are expecting, and the .ipynb file will be picked up instead of trying to open a .py file too.

I was having the same issue and I found out other ways to import the notebook that avoid this error, without needing to follow all the process recommended before (creating a new notebook, etc).

You need to first install a library: pip install import-ipynb

Then, import it in your notebook: import import_ipynb

And finally you can import your file: import WaterfallViz

Related