Note: This answer was intended for a very specific question. For most programmers coming here from a search engine, this is not the answer you are looking for. Typically you would structure your files into packages (see other answers) instead of modifying the search path.


By default, you can't. When importing a file, Python only searches the directory that the entry-point script is running from and sys.path which includes locations such as the package installation directory (it's actually a little more complex than this, but this covers most cases).

However, you can add to the Python path at runtime:

# some_file.py
import sys
# caution: path[0] is reserved for script path (or '' in REPL)
sys.path.insert(1, '/path/to/application/app/folder')

import file
Answer from Cameron on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-import-module-from-different-directory
Python – Import module from different directory - GeeksforGeeks
August 3, 2026 - In Python, a module is simply a ".py" file that contains code (functions, classes, or variables). By default, Python only searches the current working directory and standard library paths for modules. So, if you try to import a module stored in another folder, Python won’t find it and will raise:
Discussions

Importing python files from different folder
There's a few different ways and talking about the specifics on a Reddit comment gets difficult fast, but if project is a Python package you can do from project.files_2 import file_2 If project is the repository root and files_2 is a package, make sure that it's installed and just do from files_2 import file_2 As a fallback solution you can use sys.path.insert to make Python aware of the files you want to import, but it's not exactly clean and I'd strongly recommend the other solutions instead. If your project is a public repository, I recommend that you post a link here for us to give more specific help. More on reddit.com
🌐 r/learnpython
6
6
September 6, 2023
Import files directly from file location - Ideas - Discussions on Python.org
Importing new modules in Python is a pain, and far from straightforward. The trivial way to import a new module would be to give the full path of the file containing the required code - which could be a python __init__ module itself, setting up a fully functional module. More on discuss.python.org
🌐 discuss.python.org
0
July 25, 2023
How to import a Python class that is in a file in the directory above?
Simplest solution: Rename your directories to have underscores instead of dashes cd to the parent directory my_project python -m my_project.create_person.make_person Basically, you want is to make a python package. There are a couple tricks to this, and it's worth a google. More on reddit.com
🌐 r/learnpython
7
3
May 22, 2024
importing from parent directory
What are you actually trying to accomplish with this? I ask because it sounds like you are trying to do something that is not possible. This is because a submodule cannot be executed independently if it depends on a parent module. In the case you illustrate, foo.py depends on bar.py from a higher level module, so cannot be run on its own. It works with run.py because when you write from L1_dir.L2_dir.foo import *, python will first import the L1_dir module, then resolves the submodule L2_dir and imports that, then resolves the foo submodule and imports that. So in that case, by the time it gets to importing the foo submodule, it has already resolved the parent package and knows this is a child of it so no import error and all dependencies are good to go. You can workaround the import error by not using relative imports but all that is going to happen would be getting another exception indicating the module isn't found. As a side note, I should mention that using from x import * is generally bad practice as it can be unclear what is being imported and has potential for conflicting names. It's not that big of a deal when its only used to reference imports within your own package/module, but I find it's best to just avoid it so as not to get in the habit. More on reddit.com
🌐 r/learnpython
7
2
December 6, 2022
🌐
Sentry
sentry.io › sentry answers › python › import files from a different folder in python
Python Import From Parent Directory and Subfolders | Sentry
Import modules from parent, child, and sibling directories using package relative imports with __init__.py or by adding paths to sys.path at runtime
🌐
Python documentation
docs.python.org › 3 › reference › import.html
5. The import system — Python 3.15.1 documentation
When a submodule is loaded using any mechanism (e.g. importlib APIs, the import or import-from statements, or built-in __import__()) a binding is placed in the parent module’s namespace to the submodule object. For example, if package spam has a submodule foo, after importing spam.foo, spam will have an attribute foo which is bound to the submodule. Let’s say you have the following directory structure:
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-import-from-parent-directory
Python - Import from parent directory - GeeksforGeeks
July 23, 2025 - ... File "C:/Users/sai mohan pulamolu/Desktop/parentdirectory/subdirectory/temp.py", line 2, in <module> ... In order to import a module, the directory having that module must be present on PYTHONPATH.
🌐
MLJAR
mljar.com › answers › import-files-from-different-folder-python
Import files from different folder in Python
To import files from parent or sibling directories, you can use package relative imports. First, you have to creaty an empty file named __init__.py in each directory to make them recognized as packages by Python:
Find elsewhere
🌐
Quentin Fortier
fortierq.github.io › python-import
How to import local modules with Python - Quentin Fortier
May 9, 2021 - The added path ‘.’ refers to the current working directory (from which Python was run) ~/Documents/code/project. Python can indeed import c.d from this directory.
🌐
Better Stack
betterstack.com › community › questions › importing-files-from-different-folders-python
Importing files from different folder in Python? | Better Stack Community
You can also use the ... You can also use the from .. import to import module or files from different folders, if the folder is in the same parent directory as the script you are running....
🌐
Syntx Scenarios
syntaxscenarios.com › home › python › how to import from parent directory in python? (top 6 ways)
How to Import from Parent Directory in Python? (Top 6 Ways)
August 16, 2026 - The cleanest option is to use relative imports inside a proper package with __init__.py files. If you just need a quick fix, you can add the parent folder to sys.path using sys, os, or pathlib.
🌐
Python.org
discuss.python.org › ideas
Import files directly from file location - Ideas - Discussions on Python.org
July 25, 2023 - Importing new modules in Python is a pain, and far from straightforward. The trivial way to import a new module would be to give the full path of the file containing the required code - which could be a python __init__ m…
🌐
YouTube
youtube.com › bytive
Importing files from different folder - YouTube
Thanks for watching this video !Don't forget to drop a like and share it with your friends !Subscribe to the Hackanon's channel for more such interesting vid...
Published: May 3, 2022
Views: 38K
🌐
GitHub
gist.github.com › MRobertEvers › 55a989b4883ea8d7715d2e156627f034
Import Python Files From Another Directory Python 3 · GitHub
Since Python will search sys.path when it reaches an import module instruction, we can include the path to that module in sys.path before calling the import. Given a folder structure like this ... This method is inspired by Section 6.4 of the Python docs. It states that the presence of an __init__.py file (may be empty) will cause python to treat the directory it is in as a Package.
🌐
iO Flood
ioflood.com › blog › python-import-from-another-directory
Python How-To | Import Libraries From Another Directory
February 4, 2024 - When working with larger projects, you might find yourself dealing with multiple dependencies that need to be managed. Python’s package managers, such as pip and conda, can help you manage these dependencies and ensure that your imports work as expected. Importing modules from different directories is just one aspect of Python’s import system.
🌐
Python for the Lab
pythonforthelab.com › blog › complete-guide-to-imports-in-python-absolute-relative-and-more
Complete Guide to Imports in Python: Absolute, Relative, and More | Python For The Lab
In short, Python will first look at whether we are trying to import, and check if it belongs to the standard library. If the folder was time instead of numpy, the behavior would have been different. Adding the __init__.py file wouldn't make a difference. Once Python knows the module is not in the standard library, it will check for external modules. First, it starts searching the current directory.
🌐
Real Python
realpython.com › absolute-vs-relative-python-imports
Absolute vs Relative Imports in Python – Real Python
May 9, 2026 - Sometimes, however, absolute imports can get quite verbose, depending on the complexity of the directory structure. Imagine having a statement like this: ... That’s ridiculous, right? Luckily, relative imports are a good alternative in such cases! A relative import specifies the resource to be imported relative to the current location—that is, the location where the import statement is. There are two types of relative imports: implicit and explicit. Implicit relative imports have been deprecated in Python 3, so I won’t be covering them here.
🌐
Pierian Training
pieriantraining.com › home › importing a module from a different directory in python
Importing a Module from a Different Directory in Python - Pierian Training
April 28, 2023 - This adds the directory containing `my_module` to the list of directories where Python searches for modules. A relative path specifies the path to the module relative to your current script.
🌐
Pythonhow
pythonhow.com › what › what-to-do-to-import-files-from-different-folder-in-python
What to do to import files from a different folder in python
For example, let's say you have the following directory structure: project/ main.py module1/ __init__.py file1.py module2/ __init__.py file2.pyAnd you want to import file1.py from module1 in main.py. You can do this by adding the path to module1 to the Python path and then using the import statement to import file1.py:
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-import-module-outside-directory
Python - Import module outside directory - GeeksforGeeks
July 12, 2025 - This program allows Python to import a module from another directory by adding that directory to the module search path using sys.path.insert().
🌐
YouTube
youtube.com › watch
Python - Importing your modules (Part 2: Import from a different folder ~7 mins! no ads) - YouTube
Hey guys, In this episode I’m going to demonstrate how to import your own python packages within various folders relative to your main python file. Feel free...
Published: July 20, 2020