ImportError: attempted relative import with no known parent package
时间: 2023-10-12 17:18:24 浏览: 169
This error occurs when you try to use a relative import in a Python module, but the parent package is not known or not importable.
For example, if you have a module called `my_module.py` in a package called `my_package`, and you try to import another module within the same package using a relative import like this:
```
from . import my_other_module
```
But if `my_package` is not installed as a package or is not in your current working directory, you will get the "ImportError: attempted relative import with no known parent package" error.
To fix this error, you need to make sure that the parent package is importable. This can be done by adding an empty `__init__.py` file to the parent directory or installing the package in your Python environment. Once the parent package is importable, the relative import should work without any issues.
阅读全文
相关推荐


















