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
🌐
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!

🌐
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/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.
🌐
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.
🌐
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.
Top answer
1 of 5
17

You have (at least) 2 Python installations, one managed by Anaconda, the other what appears to be an official Python.org Mac build installed system-wide. The pip command on the command-line is the one tied to the Python.org Mac build.

pip is a script that is tied to a specific Python installation, and there can be multiple versions of the script installed in different locations, and is usually also installed with pipX and pipX.Y to match the X.Y version indicator of the Python version it is tied to. For Python 3.6, that means the same script would also be available as pip3 and pip3.6. (This also means that pip can be connected to Python 2 or Python 3, depending on your exact OS setup. It is not a given that pip, without a version number, installs into Python 2.x as some answers may claim).

Note that when you run a command without a path in your shell, (such as pip as opposed to /usr/bin/pip), you are asking your shell to find the command for you in a number of locations, listed in the PATH environment variable. The first location in the PATH list with that command is then fixed. which -a <command> would tell you all possible PATH-registered locations that the command can be found in. You can always use the full path to a command to bypass the PATH search path.

You can always verify what Python version the pip command is connected to with:

pip -V

which will output the version of pip and the location it is installed with. It'll print something like

pip pipX.pipY path/to/pythonX.Y/site-packages/pip (python X.Y)

where pipX.pipY is the pip version number and path/to/pythonX.Y tells you what Python installation this is for.

You can try to match this with the Python version by running

python -m site

which outputs the Python module search path for that Python version. Python can be run with python, pythonX and pythonX.Y too, and is subject to the same PATH search.

Note the -m switch there, that instructs Python to find a module in it's module search path and execute it as a script. Loads of modules support being run that way, including pip. This is important as that helps avoid having to search for a better pip command if you already can start the right Python version.

You have several good options here:

  • Since you are using Anaconda, you could look for a conda package for the same project. There is such a package for wfdb. Install it with

      conda install wfdb
    

    Anaconda aims to give you a wider software management experience that includes a broader set of software options than just the Python PyPI ecosystem, and conda packages usually manage more things than just the Python package.

    Conda packages are usually maintained by a different set of developers from the package itself, so there may be a newer version available on PyPI (requiring pip install) than there is on Conda.

    This is not an option for all Python packages, if there is no conda package you have to use pip. See Installing non-conda packages.

  • you can use the conda command to create a conda environment. Once you have an environment created, you can activate it with

      source activate <name_of_cenv>
    

    to alter your PATH settings. With the envirnoment 'active' the first directory listed on your PATH is the one for the conda environment and the pip command will be the one tied to that environment.

    Note that a conda environment gives you an isolated environment for a specific project, keeping the library installation separate from the rest of your Python packages in the central site-packages location. If you want to install a package for all of your Anaconda Python projects, don't use a conda environment.

  • Use the Anaconda Python binary to run pip as a module; when you can run /path/to/python or pythoncommand to open the right Python version, you can use that same path to run /path/to/python -m pip ... instead of pip ... to be absolutely certain you are installing into the correct Python version.

  • Look for a better pip command, with which -a pip or which -a pip3.6, etc. But if you already know the Python binary, look in the same bin location for pip. If you have anaconda/bin/python, then there probably is a anaconda/bin/pip too.

2 of 5
3

which python

gives the you the PATH to python

and then /path/to/python -m pip install thepackagetobeinstalled

Many thanks @MartijnPieters