Because the first statement, from.mymodule import myfunction, utilises a dot to indicate that the module to import is located in the same directory as the current module, it is referred to as a relative import. When importing modules into another package, which is a directory containing a collection of modules, this syntax is used. The current package is represented by the dot in this instance.
Because it defines the module to import using its whole name, the second statement, from mymodule import myfunction, is referred to as an absolute import. This syntax is used to import modules that are contained in a different package or that are not currently part of the current package.
When a relative import is used in a module that is not a part of a package, the error message "ImportError: tried relative import with no known parent package" is displayed. A directory is considered to be a package if it has the __init .py file, which identifies the directory as such. The interpreter cannot detect the relative path to the module to import if the current module is not a component of a package, which results in the error.
When the interpreter is unable to locate the module to import, the message "ModuleNotFoundError: No module called "mymodule"" is raised. The module may not be installed, it may not be in the same directory as the current module, it may not be in one of the directories mentioned in the Pythonpath variable.
Master the art of Data Science with Python and unlock the power of insights.