from .data import sql_data ImportError: attempted relative import with no known parent package
时间: 2023-10-26 15:45:16 浏览: 43
This error occurs when you try to do a relative import in a module that doesn't have a known parent package. To fix this error, you need to make sure that the module you're importing from is in a package and that the package is on the Python path.
One way to fix this error is to use an absolute import instead of a relative import. For example, if you have a package called "mypackage" and a module called "mymodule" that needs to import a module called "sql_data", you can use an absolute import like this:
from mypackage.data import sql_data
Alternatively, you can make sure that the module you're importing from is in a package. To do this, you need to create an empty __init__.py file in the directory that contains the module. This tells Python that the directory is a package and allows you to do relative imports.
Once you've done this, you can use a relative import like this:
from .data import sql_data
Note that the dot before "data" indicates that you're doing a relative import. The dot represents the current package or module, so this import statement is equivalent to "from mypackage.mymodule.data import sql_data".