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(1, '/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.

Answer from honeyspoon on Stack Overflow
๐ŸŒ
Jupyter Notebook
jupyter-notebook.readthedocs.io โ€บ en โ€บ stable โ€บ examples โ€บ Notebook โ€บ Importing Notebooks.html
Importing Jupyter Notebooks as Modules โ€” Jupyter Notebook 7.6.3 documentation
If all of your notebook cells are pure-Python, this step is unnecessary. ... class NotebookLoader(object): """Module Loader for Jupyter Notebooks""" def __init__(self, path=None): self.shell = InteractiveShell.instance() self.path = path def load_module(self, fullname): """import a notebook as a module""" path = find_notebook(fullname, self.path) print("importing Jupyter notebook from %s" % path) # load the notebook object with io.open(path, 'r', encoding='utf-8') as f: nb = read(f, 4) # create the module and add it to sys.modules # if name in sys.modules: # return sys.modules[name] mod = type
Discussions

How to import a .py file from a directory
I am trying to import a .py file into my jupyter notebook. using the following code , but it is throwing an error. I have also included init.py file in the directory import sys import os sys.path.append(os.path.abspath("/Users/hp/Documents/AFR")) import test_standard.py output No module named ... More on discourse.jupyter.org
๐ŸŒ discourse.jupyter.org
2
0
March 20, 2021
Importing local .py files into jupyter notebook?
Just add the root (where you have utils) to python path before starting jupyter. More on reddit.com
๐ŸŒ r/Jupyter
9
1
December 18, 2021
How to import functions from a .py file into a .ipynb file?
Well why are you trying to import from make_dataset if that is not the file name? You should import from whatever the file name actually is. More on reddit.com
๐ŸŒ r/learnpython
3
2
September 12, 2023
How can I import code from the parent directory into my notebook?
Are you able to print the working directory? os.getcwd() Perhaps that might offer a clue as to where the notebook is running. Are you in an IDE that is setting the sources directory? More on reddit.com
๐ŸŒ r/learnpython
15
3
October 14, 2022
๐ŸŒ
Medium
medium.com โ€บ @pablosjv โ€บ importing-local-python-modules-into-jupyter-notebooks-87336b2d7746
Importing local Python modules into Jupyter Notebooks | Medium
November 25, 2021 - This is an extension that is installed by default with Jupyter. It allow us (as its name suggest) to autoreload the imported modules when there is any changes. Otherwise, you will need to restart the kernel. The second part is to add the path to your source code to your PYTHONPATH so it can be imported.
๐ŸŒ
Saturn Cloud
saturncloud.io โ€บ blog โ€บ how-to-import-python-file-as-module-in-jupyter-notebook
How to Import Python File as Module in Jupyter Notebook | Saturn Cloud Blog
May 1, 2026 - The next step is to save the Python file with a .py extension. This is important because Python will only recognize files with a .py extension as Python modules. The Python file you created in step 1 should be moved to the same directory as your Jupyter notebook.
๐ŸŒ
Jupyter Notebook
jupyter-notebook.readthedocs.io โ€บ en โ€บ 4.x โ€บ examples โ€บ Notebook โ€บ rstversions โ€บ Importing Notebooks.html
Importing Jupyter Notebooks as Modules โ€” Jupyter Notebook 4.4.1 documentation
If all of your notebook cells are pure-Python, this step is unnecessary. class NotebookLoader(object): """Module Loader for Jupyter Notebooks""" def __init__(self, path=None): self.shell = InteractiveShell.instance() self.path = path def load_module(self, fullname): """import a notebook as a module""" path = find_notebook(fullname, self.path) print ("importing Jupyter notebook from %s" % path) # load the notebook object with io.open(path, 'r', encoding='utf-8') as f: nb = current.read(f, 'json') # create the module and add it to sys.modules # if name in sys.modules: # return sys.modules[name]
๐ŸŒ
PyPI
pypi.org โ€บ project โ€บ importnb
importnb imports notebooks as python modules.
the importnb command line interface mimics python's. it permits running notebooks files, modules, and raw json data. the commands below execute a notebook module and file respectively. importnb -m Untitled # call the Untitled module as __main__ ...
      ยป pip install importnb
    
Published: Nov 02, 2023
Version: 2023.11.1
๐ŸŒ
Jupyter Community Forum
discourse.jupyter.org โ€บ meta
How to import a .py file from a directory - Meta - Jupyter Community Forum
March 20, 2021 - I am trying to import a .py file into my jupyter notebook. using the following code , but it is throwing an error. I have also included init.py file in the directory import sys import os sys.path.append(os.path.abspath("/Users/hp/Documents/AFR")) import test_standard.py output No module named ...
Find elsewhere
๐ŸŒ
YouTube
youtube.com โ€บ watch
Python module creation and importing in Jupyter notebook - YouTube
In JupyterLab, you can import user-created modules by exporting the Notebook. This will download the .py file to your computer. The downloaded file can be im...
Published: September 6, 2022
๐ŸŒ
Python Like You Mean It
pythonlikeyoumeanit.com โ€บ Module5_OddsAndEnds โ€บ Modules_and_Packages.html
Import: Modules and Packages โ€” Python Like You Mean It
A module is simply a text file named with a .py suffix, whose contents consist of Python code. A module can be imported into an interactive console environment (e.g. a Jupyter notebook) or into another module. Importing a module executes that moduleโ€™s code and produces a module-type object instance.
๐ŸŒ
YouTube
youtube.com โ€บ watch
How to Import and Run Python File in Jupyter Notebook (2024) - YouTube
In this video, I'll show you how you can import python files in jupyter notebook, and how you can run python files in jupyter notebook.Jupyter notebook is a ...
Published: June 5, 2024
๐ŸŒ
Interactive Brokers
interactivebrokers.com โ€บ campus โ€บ ibkr-quant-news โ€บ python-importing-an-ipynb-file-jupyter-notebook-from-another-ipynb-file
Python: Importing an ipynb File (Jupyter Notebook) from Another ipynb File
February 9, 2023 - It will avoid occasional mistakes ... to name a few. To import an ipynb file in another ipynb file, we need to install import-ipynb python package which is apapted exactly to our purpose....
๐ŸŒ
Saturn Cloud
saturncloud.io โ€บ blog โ€บ how-to-import-jupyter-notebooks-to-another-jupyter-notebook
How to Import Jupyter Notebooks to Another Jupyter Notebook | Saturn Cloud Blog
May 1, 2026 - You can use the %run command to execute a Jupyter Notebook from within another notebook. Using the import_ipynb module - The import_ipynb module allows you to import a Jupyter Notebook as a module and use its code in another notebook.
๐ŸŒ
GitHub
github.com โ€บ ipython โ€บ ipynb
GitHub - ipython/ipynb: Package / Module importer for importing code from Jupyter Notebook files (.ipynb) ยท GitHub
A python package providing an easy way to explicitly import Jupyter Notebooks files (.ipynb) the same way you would import regular .py files.
๐ŸŒ
Tanso Biosciences
tansobio.com โ€บ home โ€บ blog โ€บ how to import a jupyter notebook like a python module
How to import a Jupyter notebook like a Python module
June 1, 2021 - By editing the config file jupyter_notebook_config.py, you can get Jupyter to virtually import a notebook like a Python module.
๐ŸŒ
YouTube
youtube.com โ€บ watch
How to import Python modules in Jupyter Notebook - YouTube
Here is the outline of the whole video-0:00 : Create a new folder greet_folder 0:12 : Open this folder in jupyter notebook0:20 : Create new Python notebook i...
Published: December 17, 2020
๐ŸŒ
Reddit
reddit.com โ€บ r/jupyter โ€บ importing local .py files into jupyter notebook?
r/Jupyter on Reddit: Importing local .py files into jupyter notebook?
December 18, 2021 -

This seems to be a very confusing topic for a lot of people, myself included, since I'm here asking about it.

I have some directory ../Project/utils/function.py

and I have another folder in ../Project/2021/my_notebook.ipynb

How do I import the function.py into the notebook? I know it has something to do with the path, but it's become very confusing for me. I just want to be able to create new projects in that 2021/ folder, and be able to import it using

from utils import function

This has to be possible, right? Is it something I can just "set and forget"? Or do I need to change the path for every new project?

๐ŸŒ
YouTube
youtube.com โ€บ watch
Import & run Python file (.py) in Jupyter Notebooks: %run %load - YouTube
AboutPressCopyrightContact usCreatorsAdvertiseDevelopersTermsPrivacyPolicy & SafetyHow YouTube worksTest new featuresNFL Sunday Ticket ยท ยฉ 2026 Google LLC
Published: December 1, 2019
๐ŸŒ
Python Data Science Handbook
jakevdp.github.io โ€บ blog โ€บ 2017 โ€บ 12 โ€บ 05 โ€บ installing-python-packages-from-jupyter
Installing Python Packages from a Jupyter Notebook | Pythonic Perambulations
Requirement already satisfied: numpy in /Users/jakevdp/anaconda/envs/python3.6/lib/python3.6/site-packages ยท For various reasons that I'll outline more fully below, this will not generally work if you want to use these installed packages from the current notebook, though it may work in the simplest cases. Here is a short snippet that should generally work: ... # Install a pip package in the current Jupyter kernel import sys !{sys.executable} -m pip install numpy
๐ŸŒ
Saturn Cloud
saturncloud.io โ€บ blog โ€บ how-to-import-code-into-jupyter-notebook-online
How to Import Code into Jupyter Notebook Online | Saturn Cloud Blog
May 1, 2026 - Replace [file URL] with the URL of the Python script or Jupyter Notebook file you want to load. Run the cell by pressing Shift+Enter. The code from the file will be loaded into the cell.
๐ŸŒ
Jupyter Notebook
jupyter-notebook.readthedocs.io โ€บ en โ€บ v7.4.6 โ€บ examples โ€บ Notebook โ€บ Importing Notebooks.html
Importing Jupyter Notebooks as Modules โ€” Jupyter Notebook 7.4.6 documentation
If all of your notebook cells are pure-Python, this step is unnecessary. ... class NotebookLoader(object): """Module Loader for Jupyter Notebooks""" def __init__(self, path=None): self.shell = InteractiveShell.instance() self.path = path def load_module(self, fullname): """import a notebook as a module""" path = find_notebook(fullname, self.path) print("importing Jupyter notebook from %s" % path) # load the notebook object with io.open(path, 'r', encoding='utf-8') as f: nb = read(f, 4) # create the module and add it to sys.modules # if name in sys.modules: # return sys.modules[name] mod = type