The issue was in the naming of my file.

I hastily named my file emailage.py and then tried to import from emailage.client.

I'm assuming that Python looked in my current directory and matched the names of the file I was working on before checking the installed third party libraries.

After renaming my file everything seems ok.

For others who run into similar problems -- beware of conflicting naming. Sometimes the simplest things trip you up the longest.

Answer from Aaron Taveras on Stack Overflow
Top answer
1 of 3
100

The issue was in the naming of my file.

I hastily named my file emailage.py and then tried to import from emailage.client.

I'm assuming that Python looked in my current directory and matched the names of the file I was working on before checking the installed third party libraries.

After renaming my file everything seems ok.

For others who run into similar problems -- beware of conflicting naming. Sometimes the simplest things trip you up the longest.

2 of 3
44

I ran into something similar and the answer from OP about namespace collision is what finally clued me in.

I was using the same name for both a sub-package (directory) and a module (file) within it.

For example I had this:

/opt/mylib/myapi
/opt/mylib/myapi/__init__.py
/opt/mylib/myapi/myapi_creds.py        # gitignored file for user/pass
/opt/mylib/myapi/myapi.py              # base module, load creds and connect
/opt/mylib/myapi/myapi_dostuff.py      # call myapi.py and do work

The script 'myapi.py' imports credentials from myapi_creds.py via this statement:

from myapi.myapi_creds import my_user, my_pass

Testing the module 'myapi.py' resulted in this error:

$ ./myapi.py
Traceback (most recent call last):
  File "./myapi.py", line 12, in <module>
    from myapi.myapi_creds import my_user, my_pass
  File "/opt/mylib/myapi/myapi.py", line 12, in <module>
    from myapi.myapi_creds import my_user, my_pass
ModuleNotFoundError: No module named 'myapi.myapi_creds'; 'myapi' is not a package

The solution was to rename myapi.py to myapi_base.py so it's name does not collide with the sub-package name.

🌐
freeCodeCamp
freecodecamp.org › news › module-not-found-error-in-python-solved
ModuleNotFoundError: no module named Python Error [Fixed]
September 12, 2022 - The following code will throw a module not found error: ... The reason for this is that we have used the wrong path to access the test1 module. The right path should be demoA.test1. When you correct that, the code works: ... For resolving an imported module, Python checks places like the inbuilt library, installed modules, and modules in the current project. If it's unable to resolve that module, it throws the ModuleNotFoundError.
Discussions

i have a problem with importing packages in python
I think it would be a lot more easy if you would copy the code including the module name. Have you installed the module with pip or conda? Are you in the right env? More on reddit.com
🌐 r/vscode
14
0
August 3, 2023
No module named 'py.io'; 'py' is not a package - but py library is installed - again
Follow-up of #10451 Hi, I am a nixpkgs contributor, and currently trying to package osxphotos to nixpkgs. While working on a dependency of a dependency named pytest-pycodestyle, I came across this ... More on github.com
🌐 github.com
3
July 13, 2024
ModuleNotFoundError: No module named 'supermodule.submodule'; 'supermodule' is not a package
🐛 Bug Reports I am working for writing Python extension, but facing import submodule error. ModuleNotFoundError: No module named 'supermodule.submodule'; 'supermodule' is not a package What do I ex... More on github.com
🌐 github.com
28
February 8, 2020
python - ModuleNotFoundError: No module named '__main__.xxxx'; '__main__' is not a package - Stack Overflow
Currently trying to work in Python3 and use absolute imports to import one module into another but I get the error ModuleNotFoundError: No module named '__main__.moduleB'; '__main__' is not a packa... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Medium
medium.com › @ryan_forrester_ › fixing-no-module-named-errors-in-python-a-complete-guide-b989b7a2bd19
Fixing ‘No Module Named’ Errors in Python: A Complete Guide | by ryan | Medium
May 14, 2025 - Import Error: No module named 'requests' # or ModuleNotFoundError: No module named 'pandas' This is the most frequent cause. Here’s how to check and fix it: # Check installed packages pip list | grep requests # Unix/Mac pip list | findstr requests # Windows # Install the missing package pip install requests # For specific versions pip install requests==2.28.1
🌐
Reddit
reddit.com › r/vscode › i have a problem with importing packages in python
r/vscode on Reddit: i have a problem with importing packages in python
August 3, 2023 -

In my python script I wrote:

import package.module
package.module.b()

for some reason it cant find the package and also calls it a module in the error

ModuleNotFoundError: No module named 'package'

i checked the spelling and the names of the module and the package

if you explain this it would me a lot thanks!

🌐
OneUptime
oneuptime.com › home › blog › how to fix 'modulenotfounderror' in python
How to Fix 'ModuleNotFoundError' in Python
January 24, 2026 - The most frequent cause is simply that the package is not installed: # This fails if requests is not installed import requests # ModuleNotFoundError: No module named 'requests'
🌐
OneUptime
oneuptime.com › home › blog › how to fix 'importerror: no module named' in python
How to Fix 'ImportError: No module named' in Python
January 26, 2026 - # This causes the error if 'requests' is not installed import requests # ModuleNotFoundError: No module named 'requests' The most common cause is simply that the package is not installed.
🌐
GeeksforGeeks
geeksforgeeks.org › python › modulenotfounderror-no-module-named-error-in-python
ModuleNotFoundError: No module named Error in Python - GeeksforGeeks
July 23, 2025 - Ensure that the module name matches the actual module name. ... Make sure your module is in the correct directory and has the right structure. If your module is part of a package, ensure that the package is properly structured, and use the correct ...
Find elsewhere
🌐
PyTutorial
pytutorial.com › how-to-solve-modulenotfounderror-no-module-named-in-python
How To Solve ModuleNotFoundError: No module named in Python …
August 11, 2026 - If this works, your core Python is fine. The issue is with third-party packages. Solving ModuleNotFoundError is straightforward. Start with installing the module using pip. Then, check your environment and virtual environment. Verify the module name and fix the Python path if needed.
🌐
PyDevTools
pydevtools.com › home › python developer tooling handbook › how to › how to fix modulenotfounderror: no module named 'package'
Fix ModuleNotFoundError: No Module Named (Any Package) | pydevtools
September 7, 2026 - The module is usually installed somewhere, just not in the environment Python used, which is why pip install can report success and the import still fails. Quick fix: run your code through uv with uv run python app.py instead of python app.py. uv run selects your project’s environment, so the packages you added with uv add are the packages your code sees. If it still fails, the diagnostic under Run one command to identify the cause names which of the five causes you have.
🌐
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 - Now we're up to speed with how the basic import statement is executed and what is the difference between absolute and relative imports we can now go ahead and discuss what to do when your Python application fails with either ModuleNotFoundError ** or** ImportError . 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 .
🌐
GitHub
github.com › pytest-dev › pytest › issues › 12606
No module named 'py.io'; 'py' is not a package - but py library is installed - again · Issue #12606 · pytest-dev/pytest
July 13, 2024 - cat /nix/store/6m4rxk7rn1ncads8mfjp55hxphzyfr2j-python3.12-pytest-8.2.2/lib/python3.12/site-packages/py.py · # shim for pylib going away # if pylib is installed this file will get skipped # (`py/__init__.py` has higher precedence) import sys import _pytest._py.error as error import _pytest._py.path as path sys.modules["py.error"] = error sys.modules["py.path"] = path __all__ = ["error", "path"] My only guess is that this file is getting imported instead of the correct pylib, causing the No module named 'py.io'; 'py' is not a package.
Author: pytest-dev
🌐
GitHub
github.com › PyO3 › pyo3 › issues › 759
ModuleNotFoundError: No module named 'supermodule.submodule'; 'supermodule' is not a package · Issue #759 · PyO3/pyo3
February 8, 2020 - 🐛 Bug Reports I am working for writing Python extension, but facing import submodule error. ModuleNotFoundError: No module named 'supermodule.submodule'; 'supermodule' is not a package What do I expected Import submodule like usual Pytho...
Author: PyO3
Top answer
1 of 7
56

.moduleB is a relative import. Relative only works when the parent module is imported or loaded first. That means you need to have proj imported somewhere in your current runtime environment. When you are are using command python3 moduleA.py3, it is getting no chance to import parent module. You can:

  • from proj.moduleB import moduleB OR
  • You can create another script, let's say run.py, to invoke from proj import moduleA

Good luck with your journey to the awesome land of Python.

2 of 7
46

Foreword

I'm developing a project which in fact is a Python package that can be installed through pip, but it also exposes a command line interface. I don't have problems running my project after installing it with pip install ., but hey, who does this every time after changing something in one of the project files? I needed to run the whole thing through simple python mypackage/main.py.

/my-project
    - README.md
    - setup.py
    /mypackage
      - __init__.py
      - main.py
      - common.py

The different faces of the same problem

I tried importing a few functions in main.py from my common.py module. I tried different configurations that gave different errors, and I want to share with you with my observations and leave a quick note for future me as well.

Relative import

The first what I tried was a relative import:

from .common import my_func

I ran my application with simple: python mypackage/main.py. Unfortunately this gave the following error:

ModuleNotFoundError: No module named '__main__.common'; '__main__' is not a package

The cause of this problem is that the main.py was executed directly by python command, thus becoming the main module named __main__. If we connect this information with the relative import we used, we get what we have in the error message: __main__.common. This is explained in the Python documentation:

Note that relative imports are based on the name of the current module. Since the name of the main module is always __main__, modules intended for use as the main module of a Python application must always use absolute imports.

When I installed my package with pip install . and then ran it, it worked perfectly fine. I was also able to import mypackage.main module in a Python console. So it looks like there's a problem only with running it directly.

Absolute import

Let's follow the advise from the documentation and change the import statement to something different:

from common import my_func

If we now try to run this as before: python mypackage/main.py, then it works as expected! But, there's a caveat when you, like me, develop something that need to work as a standalone command line tool after installing it with pip. I installed my package with pip install . and then tried to run it...

ModuleNotFoundError: No module named 'common'

What's worse, when I opened a Python console, and tried to import the main module manually (import mypackage.main), then I got the same error as above. The reason for that is simple: common is no longer a relative import, so Python tries to find it in installed packages. We don't have such package, that's why it fails.

The solution with an absolute import works well only when you create a typical Python app that is executed with a python command.

Import with a package name

There is also a third possibility to import the common module:

from mypackage.common import my_func

This is not very different from the relative import approach, as long as we do it from the context of mypackage. And again, trying to run this with python mypackage/main.py ends similar:

ModuleNotFoundError: No module named 'mypackage'

How irritating that could be, the interpreter is right, you don't have such package installed.

The solution

For simple Python apps

Just use absolute imports (without the dot), and everything will be fine.

For installable Python apps in development

Use relative imports, or imports with a package name on the beginning, because you need them like this when your app is installed. When it comes to running such module in development, Python can be executed with the -m option:

-m mod : run library module as a script (terminates option list)

So instead of python mypackage/main.py, do it like this: python -m mypackage.main.

🌐
Team Treehouse
teamtreehouse.com › community › keep-getting-error-modulenotfounderror-no-module-named-hellopy-hello-is-not-a-package
Keep getting error ModuleNotFoundError: No module named 'hello.py'; 'hello' is not a package (Example) | Treehouse Community
April 19, 2020 - Libby hello, Libby Libby is learning Have a great day Libby1 Traceback (most recent call last): File "<stdin>", line 1, in <module> ModuleNotFoundError: No module named 'hello.py'; 'hello' is not a package
🌐
CodeWithHarry
codewithharry.com › blogpost › solved-modulenotfounderror-no-module-named-in-python
[Solved] ModuleNotFoundError: no module named ' ' in Python | Blog | CodeWithHarry
The error message 'ModuleNotFoundError: No module named x' typically occurs when you try to import a module or package named 'x' that Python cannot find in its search paths.
🌐
Materials Science Community Discourse
matsci.org › ase
ModuleNotFoundError: No module named 'ase.build'; 'ase' is not a package - ASE - Materials Science Community Discourse
August 6, 2022 - Hi, Although i am able to run ase using the terminal however when I use an editor such as vs code or sublime I get the following error: ModuleNotFoundError: No module named ‘ase.build’; ‘ase’ is not a package Could yo…
🌐
Python.org
discuss.python.org › python help
Newbie package question - Python Help - Discussions on Python.org
July 16, 2021 - I’m trying to create my very first python package. However, I’m not sure what I’m doing wrong. I created a subfolder “pack” containing 3 files: __init__.py: (empty file) printer.py: def say_hello(): print( 'hello world' ) main.py: import printer def run(): printer.say_hello() Then in the root folder, I have a file test.py that tries to use the package: from pack import main main.run() When I run test.py, I get an error: ModuleNotFoundError: No module named 'printer'
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-fix-the-module-not-found-error
How to Fix The Module Not Found Error? - GeeksforGeeks
April 28, 2025 - Check if the module name and spelling are correct or not ... Whenever you encounter "ModuleNotFoundError" can check if the imported modules are installed in your Python environment by using 'try' and 'except' blocks to handle the error gracefully.
🌐
Itsourcecode
itsourcecode.com › home › modulenotfounderror: no module named, 8 fixes (2026)
ModuleNotFoundError: No Module Named, 8 Fixes (2026)
July 12, 2026 - Both can be true at the same time, because Python has many environments, and the package is installed in one of them, just not the one your script is running in. This guide walks through every cause, gives you the exact fix, and ends with a diagnostic command sequence that solves 95% of cases in under a minute. Updated June 2026, virtual environments are now standard practice, and the new uv package manager has changed how fast Python tooling can be. 📌 Quick answer (TL;DR): ModuleNotFoundError: No module named 'X' means Python can’t find the package X on its import path.