Relative imports in Python 3

I want to import a function from another file in the same directory.

Usually, one of the following works:

from .mymodule import myfunction
from mymodule import myfunction

...but the other one gives me one of these errors:

ImportError: attempted relative import with no known parent package
ModuleNotFoundError: No module named 'mymodule'
SystemError: Parent module '' not loaded, cannot perform relative import

Why is this?

← Назад к списку