python3: ImportError: No module named xxxx [duplicate]

TL;DR: Relative imports are gone. Use absolute imports instead.

Either use:

from Phone.Pots import Pots

or:

from .Pots import Pots

The problem occurs because Pots is part of the Phone package: there is no module named Pots, there's a module named Phone.Pots.

Python 2 had a feature called relative imports that let you write import Pots even if that was not technically correct.

Relative imports however are a source of problems and confusion:

  • Who reads the code cannot immediately say whether the import is from a package or not.
  • How come the module is named Phone.Pots, but I can use import Pots? This is highly inconsistent.
  • What if the submodule shadows a name of another module?

For these reasons, relative imports were removed from Python 3.


You can get rid of relative imports from Python 2 by using a __future__ import:

from __future__ import absolute_import