Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
import module error
#1
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
Reply
#2
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
Reply
#3
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'
Reply
#4
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.
Reply
#5
@snippsat

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  is import cointegration_analysis a recognized module mitcht33 1 424 Nov-06-2023, 09:29 PM
Last Post: deanhystad
  problem in import module from other folder akbarza 5 1,380 Sep-01-2023, 07:48 AM
Last Post: Gribouillis
  can not import anaconda pandas module. PySpark pandas module is imported!! aupres 0 710 Aug-06-2023, 01:09 AM
Last Post: aupres
  Error on import: SyntaxError: source code string cannot contain null bytes kirkwilliams2049 7 6,596 Aug-03-2023, 06:00 PM
Last Post: Gribouillis
  Import a module one step back of the path prathampatel9 1 1,061 Sep-21-2022, 01:34 PM
Last Post: snippsat
  Cryptic Error with import statement Led_Zeppelin 2 2,526 Jan-11-2022, 01:13 PM
Last Post: Led_Zeppelin
  Install any library via pip get an error cannot import name 'SCHEME_KEYS' from 'pip. Anldra12 2 10,598 Jan-04-2022, 01:05 PM
Last Post: Anldra12
  Import a module for use in type hint? Milosz 0 1,476 Nov-08-2021, 06:49 PM
Last Post: Milosz
  Can't install nor import delorean module Tek 3 2,792 Oct-27-2021, 03:32 AM
Last Post: Tek
  import module with syntax error Skaperen 7 5,252 Jun-22-2021, 10:38 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020