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
🌐
GitHub
gist.github.com β€Ί MRobertEvers β€Ί 55a989b4883ea8d7715d2e156627f034
Import Python Files From Another Directory Python 3 Β· GitHub
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.
Discussions

python - How to import from the __init__.py in the same directory? - Stack Overflow
Suppose I have a module rules with the following structure: rules β”œβ”€β”€ conditions.py β”œβ”€β”€ __init__.py In the script conditions.py, I'd like to import a class called RuleParserError defined in __init... More on stackoverflow.com
🌐 stackoverflow.com
if I use __init__.py to make a directory of modules importable, can I still do 'from <directory> import <module> ?
Yes. If that directory containing the init is in a location if will found when you import it then you can import whichever modules you like from it. If the directory is in the same location as you were able to import the files from before this will be the case. Having empty inits and consumers of a package only importing what they need is very common. More on reddit.com
🌐 r/learnpython
6
3
March 8, 2024
importing a module from a different folder
Create an empty file called __init__.py inside every folder to turn them into python packages. Then inside the main2.py do this from project.folder1 import main1 Then you can main1.(whatever the name the function is) More on reddit.com
🌐 r/learnpython
8
1
October 9, 2022
what can I put in __init__.py to make them useful
Lets say you have the following structure: - main.py - module.py With code in each file. This works fine. At some point you need to break up module.py into smaller chunks, like: - main.py - module/ - __init__.py - gui.py - encoding.py or something similar. However, because "module" is now a directory instead of a file, you can't "put code in it". The contents of __init__.py "belong" to the same namespace as module, so if module/__init__.py contains the following code: SOME_VAR = 5 then in main.py you can do: from module import SOME_VAR print(SOME_VAR + 37) Adding due to popularity: Because of the above, it's common to see __init__.py used for package-related variables (all the dunders like __author__, __version__, etc.) as well as "up-importing". "Up-importing" is a way to balance a simple user interface with a practical development layout. For example, it's not uncommon to put classes in their own module, so you might ahve: package/ models/ api.py db.py user.py and so on. However, if you do this, then the user needs to: from package.models.api import MyAPI from package.models.db import UserTable ... So instead, you make a package/__init__.py that contains the above (what you don't want to force the user to type): from package.models.api import MyAPI from package.models.db import UserTable ... and then the user can now do: from package import MyAPI, UserTable, ... Because all those objects have been "up-imported" into the top-level package namespace. For similar reasons, this is a good place to define __all__ = [], if you need it. More on reddit.com
🌐 r/learnpython
19
93
August 30, 2024
🌐
Finxter
blog.finxter.com β€Ί home β€Ί learn python blog β€Ί python β€” how to import modules from another folder?
Python - How to Import Modules From Another Folder? - Be on the Right Side of Change
July 18, 2023 - The most Pythonic way to import a module from another folder is to place an empty file named __init__.py into that folder and use the relative path with the dot notation. For example, a module in the parent folder would be imported with from ...
🌐
Python documentation
docs.python.org β€Ί 3 β€Ί reference β€Ί import.html
5. The import system β€” Python 3.15.1 documentation
Regular packages are traditional packages as they existed in Python 3.2 and earlier. A regular package is typically implemented as a directory containing an __init__.py file. When a regular package is imported, this __init__.py file is implicitly executed, and the objects it defines are bound to names in the package’s namespace.
🌐
CodeRivers
coderivers.org β€Ί blog β€Ί python-import-from-another-directory
Python Import from Another Directory: A Comprehensive Guide - CodeRivers
August 8, 2026 - As mentioned earlier, an __init__.py file makes a directory a Python package. You can use it to perform initialization code for the package and also to control what gets imported when the package is imported.
🌐
Excendra
excendra.com β€Ί home β€Ί blogs β€Ί python import from another directory: the ultimate developer guide
Python Import From Another Directory Complete Guide
February 12, 2026 - This structure becomes even more important when projects grow across multiple folders, which is where python import from another directory becomes a critical skill. A Python package is a collection of modules grouped inside a directory. The presence of an __init__.py file inside the folder tells Python that the directory should be treated as a package.
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί python-import-module-from-different-directory
Python – Import module from different directory - GeeksforGeeks
August 3, 2026 - # main.py import sys sys.path.insert(0, "../Folder_2") # add Folder_2 path to search list import module1 print(module1.add(5, 3)) # Output: 8 module1.odd_even(10) # Output: Even Β· Explanation: Here, sys.path.insert(0, "../Folder_2") tells Python where to look for module1.py. Instead of modifying code, you can set the PYTHONPATH environment variable, so Python knows where to look. ... For larger projects, the best way to organize code is by making folders into packages. A package is simply a folder that contains an __init__.py file (can be empty).
Find elsewhere
🌐
iO Flood
ioflood.com β€Ί blog β€Ί python-import-from-another-directory
Python How-To | Import Libraries From Another Directory
February 4, 2024 - Each string in this list is a directory on your system. When you try to import a module, Python checks each of these directories in order for a file that matches the name of the module. In Python, a directory is considered a package if it contains an __init__.py file.
🌐
Reddit
reddit.com β€Ί r/learnpython β€Ί if i use __init__.py to make a directory of modules importable, can i still do 'from import ?
r/learnpython on Reddit: if I use __init__.py to make a directory of modules importable, can I still do 'from <directory> import <module> ?
March 8, 2024 -

so If I have a directory called foo with a bunch of modules in it (bar.py, baz.py) and an empty __init__.py in teh dir, can I still do from foo import baz from my main .py script?

I want to organize all my modules in a dir, but I don't want to always import them all, or a fixed set of them (which seems to be the purpose of __init__.py). I usually only want to import some of them depending on the functionality of the main script.

So my intent is less to create an consistently importable package from a dir, but rather just organize my project so I don't have a bunch of .py modules in the root of my project dir.

🌐
RunxBuild
runxbuild.com β€Ί home β€Ί blog β€Ί python import from another directory: why it fails and what to do
Python Import From Another Directory: Why It Fails and What to Do
August 10, 2026 - Add __init__.py to test directories only if you need test modules with colliding names across directories. Otherwise leave them out β€” pytest handles it. The packaging question becomes concrete at deploy time, because a container has none of the assumptions your laptop had. FROM python:3.12-slim WORKDIR /app # Dependencies first, so this layer caches COPY pyproject.toml ./ COPY src/ ./src/ RUN pip install --no-cache-dir . # Absolute imports work because the package is installed CMD ["python", "-m", "myapp.app"]
🌐
Python Pool
pythonpool.com β€Ί home β€Ί tutorials β€Ί import python from another directory: packages and project layout
Import Python from Another Directory: Packages and Project Layout
July 13, 2026 - If several files need the same path edit, that is a sign the project should be packaged properly. For applications and libraries, create a package, add __init__.py where appropriate, use absolute imports, and run modules from the project root.
🌐
CodeRivers
coderivers.org β€Ί blog β€Ί python-import-file-from-another-directory
Python: Importing Files from Another Directory - CodeRivers
August 8, 2026 - Without __init__.py, Python 3.3+ will treat the directory as a namespace package β€” a more advanced feature with different behavior. For most projects, including an explicit __init__.py is the safer and more predictable choice. The sys.path list can be modified to include the directory from which you want to import a file.
🌐
Zean
zean.be β€Ί articles β€Ί definitive-guide-python-imports
The definitive guide to Python import statements - Zean Qin
An __init__.py file has 2 functions. ... the script we are writing (or the directory from which we run the Python interactive interpreter), that module needs to be in a package....
🌐
Leapcell
leapcell.io β€Ί blog β€Ί how-to-import-modules-from-another-directory-in-python
How to Import Modules from Another Directory in Python | Leapcell
July 25, 2025 - Scope: This method affects all ... structured as a package with an __init__.py file, you can use relative imports to access modules in parent or sibling directories......
🌐
Career Karma
careerkarma.com β€Ί blog β€Ί python β€Ί what is __init__.py? : a guide
What is __init__.py? | Career Karma
December 30, 2020 - If you want to import a file from another directory, that directory must contain a Python __init__.py file.
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί python-import-module-outside-directory
Python - Import module outside directory - GeeksforGeeks
July 12, 2025 - Python Β· # defining a function ... to import module outside directory. __init__.py method mark a folder as a Python package, allowing Python to recognize it as a valid source of modules....
🌐
My Website
enersection.io β€Ί home β€Ί python import module from another directory
Python Import Module From Another Directory
May 19, 2026 - The leading dot indicates β€œstart from the current package”. Even so, relative imports only work when the module is executed through the -m flag or as part of a package. Running python src/main.py directly will cause a ValueError: Attempted relative import with no known parent package. Not obvious, but once you see it β€” you'll see it everywhere. ... Forgetting __init__.py files – These files mark directories as packages.
🌐
CodeGenes
codegenes.net β€Ί blog β€Ί how-to-import-python-files-from-another-directory
Importing Python Files from Another Directory β€” codegenes.net
my_package/ β”œβ”€β”€ __init__.py β”œβ”€β”€ module1.py └── sub_package/ β”œβ”€β”€ __init__.py └── module2.py Β· In module2.py, you can use a relative import to import module1: ... The .. indicates the parent directory of the current module.