Why am I getting the Python Error “ImportError: No module named py”?

Question: Why am I getting the following error in Python “ImportError: No module named py”?

Simple answer: Somewhere, one of your imports ends in “.py”  Deleting that should solve the issue.

 

Example 1

import test.py

Python is trying to import the package named “test” with a module named “py” that doesn’t exist within the file “test.py”

Correct way of importing “test.py”

import test

 

Example 2

The Qt Designer allows you to subclass/extend a widget by “promoting” the base class and then specifying a header file that contains your defined class.  If the header file variable in Qt Designer has “.py” you also get the error when your GUI is compiled.  The incorrect inclusion of “testlistview.py”:

Correct way:

 

Further reading: