简体   繁体   中英

Python: “ImportError: attempted relative import with no known parent package”

I'm working on the capstone project for Udacity's Full Stack Web Developer. I consider myself a beginner developer so please be kind: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] 1

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:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM