Imagine the following directory structure for a package named app1:
/app1 /__init__.py /models.py /tests.py
Now, in Python 3, let's run the following in the parent directory of app1:
$ echo "import models" > app1/tests.py $ python -m app1.tests Traceback (most recent call last): ... omitted ... ImportError: No module named 'models' $ echo "from . import models" > app1/tests.py $ python -m app1.tests # Successfully imported
Within a package, you should use explicit relative imports when referring to a sibling module. You can omit __init__.py in Python 3, though it is commonly used to identify a package.
In Python 2, you can use import models to successfully import the models.py module. However, it is ambiguous ...