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 - # 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).
Discussions

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
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 Class from another python file?

At the top of your script, add the following:

import sys
print(sys.path)

This will help you understand why certain imports work. sys.path is a list of directories. When you say import foo, Python will look for something called "foo" in each of the directories in sys.path. The first directory in sys.path is typically the directory that contains the script you are executing (but this can change depending on exactly how you are executing the script).

If you can show the full structure of your project and exactly how you are running your script, then I can give you advice on the best way to do your imports.

More on reddit.com
🌐 r/learnpython
11
1
October 24, 2015
[Python][Pandas] Reading a .csv file from a folder on my hard drive and setting it to a variable

This is because \r is the carriage return character. When that's found in a string, it moves the "reader" back to the beginning of the line. Your string, therefore, is read as 'adiation_data.csv', which doesn't exist. You can precede your string with r to have metacharacters not be interpolated, as in:

dataset_all=read_csv(r'C:\Users\Jason\Desktop\open_datasets\radiation_data.csv')
More on reddit.com
🌐 r/learnpython
12
5
August 20, 2013
🌐
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
🌐
GitHub
gist.github.com › MRobertEvers › 55a989b4883ea8d7715d2e156627f034
Import Python Files From Another Directory Python 3 · GitHub
That means we will be able to import <directory> as a module. Notice that one of the directories in sys.path by default is the directory that the python file launched from. We can use that information to interpret the line When importing the package, Python searches through the directories on sys.path looking for the package subdirectory.
🌐
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…
Find elsewhere
🌐
Better Stack
betterstack.com › community › questions › importing-files-from-different-folders-python
Importing files from different folder in Python? | Better Stack Community
Alternatively, you can use the PYTHONPATH environment variable to add the path to the folder containing the file you want to import. You can also use the importlib.import_module() function to import modules from different folders by providing ...
🌐
Quora
quora.com › How-do-I-import-a-py-file-into-another-folder
How to import a .py file into another folder - Quora
Answer (1 of 3): An alternate solution to that suggested by David Mankins would be to add the path of the Python file you want to import to the PYTHONPATH environment variable. I recommend this solution only if you have a folder/directory where you want to keep all your own Python libraries, whic...
🌐
Pythonin1minute
pythonin1minute.com › how-to-import-from-another-folder-in-python
How To Import From Another Folder In Python? | Python in 1 minute
By default Python does not allow importing files from arbitrary directories, but there is a workaround: you can add the directory to your PYTHONPATH env var or insert it into the sys.path variable.
🌐
IncludeHelp
includehelp.com › python › importing-files-from-different-folder.aspx
Importing files from different folder in Python
December 4, 2019 - In order to learn about importing the files from a different folder, assume that the project is having the below folder structure, Project_name __init__.py modules __init__.py file.py sub_module_1 __init__.py file1.py · In the above structure, there is an __init__.py file added to all the folders. This file ensures that the folder is included as a python package.
🌐
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:
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-move-files-and-directories-in-python
How to move Files and Directories in Python - GeeksforGeeks
July 12, 2025 - This can be achieved using shutil.move() function from shutil module. shutil.move() method Recursively moves a file or directory (source) to another location (destination) and returns the destination.
🌐
Quentin Fortier
fortierq.github.io › python-import
How to import local modules with Python - Quentin Fortier
May 9, 2021 - Python can indeed import c.d from this directory. This solution works regardless of the directory used to run Python: ~/Documents/code/project$ cd ../.. ~/Documents$ python3 code/project/src/a/b.py ['/home/qfortier/Documents/code/project/src/a', ..., 'code/project'] It should also work on a different computer, with a different filesystem or OS, thanks to Pathlib.
🌐
Thinkincode
thinkincode.net › python › python-how-to-import-from-another-directory
Import Python file from another directory | ThinkInCode
Posted in Python by Dirk - last update: Feb 15, 2024 · If you want to import a file from another directory, you can add the part from the other directory to the system path using sys.path.append.
🌐
GeeksforGeeks
geeksforgeeks.org › python › importing-python-functions-from-other-scripts
Importing Python Functions from Other Scripts - GeeksforGeeks
July 23, 2025 - In this example, we have two scripts. The first script (`geometry.py`) contains functions related to geometry. The second script (`main.py`) imports only the `area_of_square` function from the geometry module using the `from geometry import area_of_square` statement.
🌐
Tutor Python
tutorpython.com › python-import-from-parent-directory
Python Import from parent directory - Tutor Python
October 19, 2023 - Then we talked about how to modify the environment variable PYTHONPATH in order to be able to import from other directories. We then finally showed how modifying sys.path can help us import modules from another directory, especially the parent directory.
🌐
Board Infinity
boardinfinity.com › blog › import-a-class-from-another-file-in-python
Import class from another file Python | Board Infinity
January 3, 2025 - The way you structure your project’s files affects how you import class in Python. Here's a breakdown: These are imports where you specify the full path from the root of your project. They are simple and clear. ... Absolute imports are preferred because they are explicit and help avoid ambiguity. These imports are used when files are within the same package or directory.
🌐
Medium
khambud.medium.com › importing-files-in-python-repository-28ab49fade37
Importing files from different directory — Python | by Diane Khambu | Medium
April 5, 2020 - Put the operation directory in PYTHONPATH environment variable. In Mac OS, you can use following cli. export PYTHONPATH=$PYTHONPATH:/Users/dichha/Projects/medium/importing_files_python/method_1/operations
🌐
GeeksforGeeks
geeksforgeeks.org › python › import-modules-from-another-folder-in-python
Import Modules From Another Folder in Python - GeeksforGeeks
July 23, 2025 - Add the path to PYTHONPATH and import module0 present in the directory and call its run function.
🌐
Analytics Vidhya
analyticsvidhya.com › home › how to import python modules from different directories?
How to Import Python Modules from Different Directories?
January 23, 2024 - Using this snippet, Python will now include the specified directory when searching for modules to import. The PYTHONPATH environment variable is a powerful tool for influencing Python’s module and package search behavior. By configuring PYTHONPATH, you can specify additional directories where Python should look for modules and packages. Unlike directly modifying sys.path within your code, setting PYTHONPATH occurs externally to Python. Typically, you configure PYTHONPATH in your shell’s configuration file or through your operating system’s environment settings.