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.

🌐
GitHub
github.com › tensorflow › tensorflow › issues › 34722
ModuleNotFoundError tensorflow.python' is not a package · Issue #34722 · tensorflow/tensorflow
November 30, 2019 - Traceback (most recent call last): File "singlestock/code.py", line 1, in import tensorflow as tf File "D:\documenten\programs\Python\3.6.7\lib\site-packages\tensorflow_init_.py", line 98, in from tensorflow_core import * File "D:\documenten\programs\Python\3.6.7\lib\site-packages\tensorflow_core_init_.py", line 40, in from tensorflow.python.tools import module_util as _module_util ModuleNotFoundError: No module named 'tensorflow.python.tools'; 'tensorflow.python' is not a package ·
Author: tensorflow
🌐
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 - { lib, buildPythonPackage, fetchFromGitHub, setuptools, pytestCheckHook, pycodestyle, py, pytest-isort }: buildPythonPackage rec { pname = "pytest-pycodestyle"; version = "2.3.1"; pyproject = true; src = fetchFromGitHub { owner = "henry0312"; repo = "pytest-pycodestyle"; rev = "refs/tags/v${version}"; hash = "sha256-ODbjjAEGI1qkK4UXQA2q4Yvi53zP/vS1Ue50uCaJ4To="; }; build-system = [ setuptools ]; dependencies = [ py pycodestyle ]; pythonImportsCheck = [ "pytest_pycodestyle" ]; nativeCheckInputs = [ pytestCheckHook pytest-isort ]; meta = { description = "pytest plugin to run pycodestyle"; license = lib.licenses.mit; homepage = "https://github.com/henry0312/pytest-pycodestyle"; maintainers = with lib.maintainers; [ sigmanificient ]; }; } The issue only happens when having pytestCheckHook, which setup pytest. I noticed a py.py appears in site-packages when pytest is installed.
Author: pytest-dev
🌐
pythontutorials
pythontutorials.net › blog › importerror-with-error-is-not-a-package
How to Fix ImportError: 'is not a package' in Python 3 – Troubleshooting Project Structure Issues
Relative imports (e.g., from . import module) only work in modules that are part of a package. If you run a script directly (e.g., python script.py), it becomes the __main__ module and is not considered part of a package.
🌐
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!

🌐
Reddit
reddit.com › r/learnpython › import error: 'x' is not a package
r/learnpython on Reddit: Import error: 'x' is not a package
April 18, 2020 -

I'm working on a program that lets the user do mad libs, and I'm importing the prompts from a file in a subdirectory (prompts being "enter a noun", for example). The file tree looks something like this:

    Mad Libs
        |
       libs
        /\
    lib 1 lib2
    /\
prompts.py text.txt

if I import from a test file in the "Mad Libs" directory, it imports just fine. But if I import from the main program, I get this error:

ModuleNotFoundError: No module named 'libs.lib 1.prompts.py'; 'libs.lib 1.prompts' is not a package

I'm using the importlib module for imports, since they're based on user-entered strings.

Any ideas what's going on here?

🌐
Python.org
discuss.python.org › python help
How to structure a APP not a package or a "project" - Python Help - Discussions on Python.org
May 1, 2024 - Hi, I’m writing a data processing app in python and I don’t know how to structure the APP to RUN it. Every guid just tells you how to structure your project to upload it to pypi but I don’t need to upload it I need to run my project. I use the usual example: helloworld/ main.py
Find elsewhere
🌐
freeCodeCamp
freecodecamp.org › news › module-not-found-error-in-python-solved
ModuleNotFoundError: no module named Python Error [Fixed]
September 12, 2022 - 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. Sometimes you do not have that module installed, so you have to install it. Sometimes it's a misspelled module, or the naming with the wrong casing, or a wrong path.
🌐
GitHub
github.com › python › importlib_resources › issues › 60
Using __name__ on a non-package module results in "not a package" error · Issue #60 · python/importlib_resources
October 21, 2020 - >>> importlib_resources.read_binary(queso.validator.tests.test_options.__name__, 'colliding questions.json') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/jaraco/Dropbox/code/yg/G/queso/.tox/py36/lib/python3.6/site-packages/importlib_resources/_py3.py", line 142, in read_binary package = _get_package(package) File "/Users/jaraco/Dropbox/code/yg/G/queso/.tox/py36/lib/python3.6/site-packages/importlib_resources/_py3.py", line 40, in _get_package raise TypeError('{!r} is not a package'.format(package)) TypeError: 'queso.validator.tests.test_options' is not a package ·
Author: python
🌐
HubSpot
community.hubspot.com › t5 › APIs-Integrations › Python-hubspot-is-not-a-package › m-p › 685700
Solved: HubSpot Community - Python 'hubspot' is not a package - HubSpot Community
July 29, 2024 - @HHawley I would maybe say, since you rebuilt the script, to double check that the module is installed and in the correct directory. Also try updating Python. There are multiple version of the API, so it may be conflicting with your current version. ... Hi, @HHawley Welcome to the community! Hey, @taran42 @MichaelC @albertsg, can you lend a hand here? Or do you have thoughts on how @HHawley can troubleshoot here? ... It does not make sense.
🌐
GitHub
github.com › pytest-dev › pytest › issues › 10428
pytest 7.2.0: ModuleNotFoundError: No module named 'py.xml'; 'py' is not a package · Issue #10428 · pytest-dev/pytest
October 25, 2022 - File ".venv/lib/python3.9/site-packages/pytest_html/html_report.py", line 11, in <module> from py.xml import html ModuleNotFoundError: No module named 'py.xml'; 'py' is not a package
Author: pytest-dev
🌐
Python documentation
docs.python.org › 3 › reference › import.html
5. The import system — Python 3.15.1 documentation
It’s important to keep in mind that all packages are modules, but not all modules are packages. Or put another way, packages are just a special kind of module. Specifically, any module that contains a __path__ attribute is considered a package.
🌐
YouTube
youtube.com › watch
How to Resolve Could Not Find a Version Error for Specific Python Package Installations? - YouTube
Learn effective troubleshooting steps to solve the "Could not find a version that satisfies the requirement Python" error when installing specific Python pac...
Published: January 13, 2025
Views: 13
🌐
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 - A python module is a single file with a .py extension. A python package is a folder that contains at least one python module.
🌐
Dagster
dagster.io › blog › python-breaking-packages
Breaking Python Packages Explained
Even though we have __init__.py, Python does not create a package. To get Python to treat our files as a package, we need to move up directory and import tree in order to have it treated as a package.