This is a very typical issue, so I will leave this here for future reference.

If I have a project called: my_project

.
└── my_project
    β”œβ”€β”€ first_folder
    β”œβ”€β”€ second_folder
    └── third_folder

What you want to do is one of these two things:

  1. PYTHONPATH (only Python)

cd ~/my_project && export PYTHONPATH=$(pwd)

change dir to root dir, and export that dir to PYTHONPATH, so when Python runs it looks in the PYTHONPATH.

  1. PATH (everything)

cd ~/my_project && export PATH=$PATH:$(pwd)

Same as above!

This needed to live somewhere since it took me a while to figure out. So for anyone in the future who needs help with this!

Answer from DUDANF on Stack Overflow
Discussions

Python doesn't find local module although it is installed and its location exists in sys.path
I installed a local module using the pyproject.toml approach by following the great tutorial by RealPython: Packaging Your Python Code With pyproject.toml | Complete Code Conversation - YouTube Although the module seems to be locally installed, I am unable to invoke it from outside the project ... More on discuss.python.org
🌐 discuss.python.org
6
0
March 23, 2023
Module not found but it's already installed
I’m fairly new to Python. I use Python 3.11.8 (what MS Azure supports, my eventual production environment) on Windows 10. I’m testing a program on Windows 10. I have created and activated my virtual environment in the cmd.exe window. My program is in c:\users\MYUSER\onedrive - ... More on discuss.python.org
🌐 discuss.python.org
8
0
March 26, 2024
ModuleNotFoundError: No module named 'Directory_one'
Hi All, I am trying to access method from another module in one of my file but I keep getting ModuleNotFoundError. This how my folder structure is: Appreciate for your help Thanks Lax More on discuss.python.org
🌐 discuss.python.org
2
0
August 26, 2021
python - Module not found - "No module named" - Stack Overflow
Here's my Python folder structure -project ----src ------model --------order.py ------hello-world.py Under src, I have a folder named model, which has a Python file called order.py, whose contents More on stackoverflow.com
🌐 stackoverflow.com
🌐
freeCodeCamp
freecodecamp.org β€Ί news β€Ί module-not-found-error-in-python-solved
ModuleNotFoundError: no module named Python Error [Fixed]
September 12, 2022 - In Python, you can import modules from other files using absolute or relative paths. For this example, I'll focus on absolute paths. When you try to access a module from the wrong path, you will also get the module not found here. Here's an example: Let's say you have a project folder called test.
🌐
Python.org
discuss.python.org β€Ί python help
Python doesn't find local module although it is installed and its location exists in sys.path - Python Help - Discussions on Python.org
March 23, 2023 - I installed a local module using the pyproject.toml approach by following the great tutorial by RealPython: Packaging Your Python Code With pyproject.toml | Complete Code Conversation - YouTube Although the module seems to be locally installed, I am unable to invoke it from outside the project directory.
🌐
Containersolutions
containersolutions.github.io β€Ί runbooks β€Ί posts β€Ί python β€Ί module-not-found
Module Not Found – Runbooks
If you are using a pre-3.3 version of Python, then it is a requirement that a Python module contains a file called __init__.py. The inclusion of the file is often forgotten about when creating modules on-the-fly, so is a frequent cause of failure. You may also want to consider whether the user you are running as has the right permissions to access the files and folders (see step 4).
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί how-to-fix-the-module-not-found-error
How to Fix The Module Not Found Error? - GeeksforGeeks
April 28, 2025 - This error occurs when you have not installed that module on your system and try to access the module that the Python interpreter cannot locate in its search path or in the Python path, If python cannot find the module you're trying to import ...
🌐
Towards Data Science
towardsdatascience.com β€Ί home β€Ί programming β€Ί how to fix modulenotfounderror and importerror
How to Fix ModuleNotFoundError and ImportError | Towards Data Science
September 13, 2020 - In most of the cases, either of the errors occur due to the fact that Python is unable to resolve the module's name in sys.path . Recall that when you call import a if the module's name was found neither in sys.modules nor in standard library, ...
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί how-to-fix-the-module-not-found-error
How to Fix The Module Not Found Error - Python
July 1, 2026 - Explanation: package may be installed globally or in another virtual environment, but not in the currently active one. 1. Check Whether the Module is Installed: You can use a try-except block to verify whether a module exists.
Find elsewhere
🌐
LabEx
labex.io β€Ί tutorials β€Ί python-how-to-address-module-not-found-errors-in-python-415764
How to address module not found errors in Python | LabEx
This can happen for a variety of reasons, such as: The module is not installed or is not in the Python path. The module is misspelled or named incorrectly. The module is located in a different directory than your script.
🌐
Python.org
discuss.python.org β€Ί python help
Module not found but it's already installed - Python Help - Discussions on Python.org
March 26, 2024 - I’m fairly new to Python. I use Python 3.11.8 (what MS Azure supports, my eventual production environment) on Windows 10. I’m testing a program on Windows 10. I have created and activated my virtual environment in the cmd.exe window. My program is in c:\users\MYUSER\onedrive - ...
🌐
Python.org
discuss.python.org β€Ί python help
ModuleNotFoundError: No module named 'Directory_one' - Python Help - Discussions on Python.org
August 26, 2021 - Hi All, I am trying to access method from another module in one of my file but I keep getting ModuleNotFoundError. This how my folder structure is: Appreciate for your help Thanks Lax
🌐
YouTube
youtube.com β€Ί watch
How to Fix Module Not Found Error in Python - ModuleNotFound Error (FIXED) - YouTube
In this video, I'll show you how you can fix the ModuleNotFound error in Python. The module not found error (ModuleNotFoundError) in python occurs when a spe...
Published: July 25, 2024
🌐
Reddit
reddit.com β€Ί r/learnpython β€Ί why do i get a modulenotfounderror?
r/learnpython on Reddit: Why do I get a ModuleNotFoundError?
September 2, 2021 -

Hey Guys,

I get a weird ModuleNotFoundError in one of my projects and i do not really understand why. So here is my Folder Structure:

Project\

| main.py

| packageabc\

| | __init__.py

| | abc.py

| | packagexyz\

| | | xyz.py

In every .py file is an abc/xyz or main class. Now the interesting part. Inside the abc.py I do an import like this:

from packagexyz.xyz import xyz

This works perfectly fine!

Inside the main.py I do an import like this:

from packageabc.abcimport abc

Now I get an ModuleNotFoundError. Error Code looks like this:

from packagexyz.xyz import xyz ModuleNotFoundError: no module named packagexyz.

So the import in the abc.py File that works perfectly when tested inside the file does not work if the abc.py file is imported. So why is that?

Top answer
1 of 2
2
You probably have a circular dependency - abc imports xyz and xyz imports abc. Python can't complete either import so it raises an error.
2 of 2
1
It's because of the way Python looks for modules. There's a list of paths that Python looks through to find modules, which automatically includes things like the place pip installs packages to. It also automatically includes the directory the executing script is in. It does not, however, automatically include the directory an imported module is in. So, if you're executing "abc.py" directly, in finds "packagexyz" just fine, since it knows to look in the "packageabc" folder for modules. If you are executing "main.py" instead, the only place it looks (besides the default and manually configured paths) is "Project", so it can't find packagexyz. There's really three ways you could fix this: Manually configuring paths You can keep the imports as you have them and simply ensure that the "packageabc" folder is always on the search path for modules. You can do so either by configuring the PYTHONPATH environment variable to include it or by appending it to sys.path in your "main.py" before importing abc. Absolute imports You could also change the import in "abc.py" to be relative to "Project" (from packageabc.packagexyz.xyz import xyz). Then your "main.py" would work the way it is. Of course, that in turn means you can no longer directly execute "abc.py" unless you manually configure "Project" to always be on the search path for modules. Relative imports You could also change "abc.py" to use relative imports (from .packagexyz.xyz import xyz, note the extra dot in front). Then your "main.py" would work the way it is, as well. You could also still directly execute "abc.py", but only if you make sure to do it in a way that Python is aware it is part of a larger package (otherwise, relative imports give you an error). Specifically, you'd always need to execute it like this: python -m packageabc.abc Rather than like this: python packageabc/abc.py
🌐
Reddit
reddit.com β€Ί r/learnpython β€Ί modulenotfounderror, but it's there
r/learnpython on Reddit: ModuleNotFoundError, but it's there
September 13, 2023 -

I'm trying to build a "portable" Python package based on those available from https://github.com/indygreg/python-build-standalone/releases.

I've extracted this into /opt/staging/ansible and pip installed ansible without issue (the main purpose of this package will be to allow staging machines to run ansible-pull).

However, I also need the 'firewall' module installed, but after installing it, Python still fails to import it. I confirmed the module library locations:

root@b-test3 /opt/staging/ansible/bin # ./python3 -m 'site'
sys.path = [
    '/opt/staging/ansible/bin',
    '/opt/staging/ansible/lib/python310.zip',
    '/opt/staging/ansible/lib/python3.10',
    '/opt/staging/ansible/lib/python3.10/lib-dynload',
    '/opt/staging/ansible/lib/python3.10/site-packages',
]
USER_BASE: '/root/.local' (doesn't exist)
USER_SITE: '/root/.local/lib/python3.10/site-packages' (doesn't exist)
ENABLE_USER_SITE: True

I even went as far as to manually target the site-packages directory:

# ./pip3 install -Ut /opt/staging/ansible/lib/python3.10/site-packages/ firewall
Collecting firewall
  Using cached firewall-0.2.0-py3-none-any.whl
Collecting boto (from firewall)
  Using cached boto-2.49.0-py2.py3-none-any.whl (1.4 MB)
Collecting ec2>=0.2 (from firewall)
  Using cached ec2-0.4.0-py2.py3-none-any.whl (6.2 kB)
Installing collected packages: boto, ec2, firewall
Successfully installed boto-2.49.0 ec2-0.4.0 firewall-0.2.0

But still...

root@b-test3 /opt/staging/ansible/bin # ./python3
Python 3.10.13 (main, Aug 26 2023, 07:12:19) [Clang 16.0.3 ] on linux
Type "help", "copyright", "credits" or "license" for more information.
Cannot read termcap database;
using dumb terminal settings.
>>> import firewall
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'firewall'
>>>

I've checked all the usual suspects I can think of. This is an Oracle Linux 8 VM, so it's got Python3.6 by default. I can install firewall there and import it no problem.

In my Python 3.10 package, I can install other modules without issue (and without any tricks). Ansible installed fine and runs as expected. I also installed pandas as a test and could import it successfully.

Anyone got any clues why firewall isn't working?

🌐
iO Flood
ioflood.com β€Ί blog β€Ί python-no-module-named
[SOLVED] 'No Module Named' Python Error Solutions
January 30, 2024 - If the path to your module is not in this list, you need to add it. You can do this by appending the path to sys.path like this: ... Replace /path/to/your/module with the actual path to your module. After adding the path, you should be able to import the module without the β€˜No Module Named’ error. Sometimes, the β€˜No Module Named’ error can be caused by Python version mismatches. This happens when a module is installed for one version of Python, but you’re trying to import it in a different version.
🌐
Prakashinfotech
prakashinfotech.com β€Ί q-and-a-module-not-found-error
What does the "Module Not Found Error" in Python indicate, and how can it be resolved?
October 27, 2025 - You’re writing a Python script ... is not installed in your Python environment. ... Install the β€œnumpy” module using pip (`pip install numpy`) to resolve the error and make the module available in your Python environment....
🌐
Semicolon
semicolon.dev β€Ί python β€Ί how-to-fix-modulenotfounderror-no-module-named
semicolon.dev is for sale β€” Buy for $4,995 or Lease to Own | GoDaddy
semicolon.dev is for sale on GoDaddy. Own it today for $4,995, or select Lease to Own. Safe & secure transactions.