Python Forum

Full Version: import module error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm learning Flask by watching a YouTube tutorial

https://www.youtube.com/watch?v=dam0GPOAvVI
https://github.com/techwithtim/Flask-Web...23/website

I'm getting an error:
Error:
ImportError: attempted relative import with no known parent package
from . import db
from flask_login import UserMixin
from sqlalchemy.sql import func
It says error is in line 1, this is my first time importing using a period at front.

But my folder structure and code is what's in Github link

from . import db
Anyone? Apparently this is a common error and easy to fix, but I can't figure it out.

When I run main.py, this is what I'm getting for errors.

Error:
Traceback (most recent call last): File "C:\Users\user\Desktop\database\main.py", line 3, in <module> app = create_app() File "C:\Users\user\Desktop\database\website\__init__.py", line 24, in create_app create_database(app) File "C:\Users\user\Desktop\database\website\__init__.py", line 38, in create_database db.create_all(app=app) TypeError: SQLAlchemy.create_all() got an unexpected keyword argument 'app'
Change create_database to this.
def create_database(app):
    if not path.exists('website/' + DB_NAME):
        with app.app_context():
            db.create_all()
        print('Created Database!')
If problem running remove debug=True in main.py.
@snippsat

Thank you that worked.
If you're getting an error when trying to import a module, make sure you have the right version installed!