[英]Python: “ImportError: attempted relative import with no known parent package”
I'm working on the capstone project for Udacity's Full Stack Web Developer.我正在为 Udacity 的全栈 Web 开发人员开发顶点项目。 I consider myself a beginner developer so please be kind:D
我认为自己是一个初学者开发者,所以请善待:D
I'm working on the backend for my project but I'm getting stuck with this error:我正在为我的项目开发后端,但我遇到了这个错误:
(env) C:\Repos\FSND_Capstone_Project\backend>flask db init Usage: flask db init [OPTIONS] Error: While importing "api", an ImportError was raised: Traceback (most recent call last): File "c:\repos\fsnd_capstone_project\backend\env\lib\site-packages\flask\cli.py", line 236, in locate_app __import__(module_name) File "C:\Repos\FSND_Capstone_Project\backend\api.py", line 9, in <module> from.database.models import setup_db, Manager, Project, Category ImportError: attempted relative import with no known parent package
I also have the following folder structure that I'm trying to create:我还尝试创建以下文件夹结构:
[Folder structure] [文件夹结构]
I don't see what the error might be.我看不出错误可能是什么。 Any tip of advice will be very well received.
任何建议都会很受欢迎。
I also attached my Github's repo link:我还附上了我的 Github 的 repo 链接:
https://github.com/jovillarroelb/FSND_Capstone_Project https://github.com/jovillarroelb/FSND_Capstone_Project
Thanks in advance!提前致谢!
Regards!问候!
You have to from database.models import setup_db
because .database.models
only works if backend is a package itself (has a __init__.py
file)您必须
from database.models import setup_db
因为.database.models
仅在后端是 package 本身时才有效(具有__init__.py
文件)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.