To solve ImportError: attempted relative import with no known parent package error follow below methods.
ERROR LOG
ImportError: attempted relative import with no known parent package
Contents
How to solve ImportError: attempted relative import with no known parent package ?
Refer the given methods to solve the issue.
Method 1: Get Rid of From Keyword
Use import
instead of from
, and make sure to use the module reference when using your imported functions. In our case, this is util. As a result, your main.py file would now look like this:
# main.py
import util
util.function_under_util()
Method 2 : Use absolute imports
Consider the directory structure as below:
. ├── project │ ├── package │ │ ├── __init__.py │ │ ├── module.py │ │ └── standalone.py │ └── setup.py
where setup.py is as below:
from setuptools import setup, find_packages
setup(
name = 'your_package_name',
packages = find_packages(),
)
Hope the above solution works.
Also read :
TypeError: ‘int’ object is not callable in Python
UnboundLocalError: local variable referenced before assignment Python