Import py file in another directory in Jupyter notebook

There is no simple way to import python files in another directory.
This is unrelated to the jupyter notebook

Here are 3 solutions to your problem

  1. You can add the directory containing the file you want to import to your path and then import the file like this:
import sys  
sys.path.insert(0, '/path/to/application/app/folder')

import file
  1. You can create a local module by having an empty __init__.py file in the folder you want to import. There are some weird rules regarding the folder hierarchy that you have to take into consideration.

  2. You can create a module for the file you wish to import and install it globally.

Leave a Comment