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
  Dynamic Module Import Error DaddyMAN 3 1,545 Jun-20-2025, 12:07 AM
Last Post: Pedroski55
  Error on import: SyntaxError: source code string cannot contain null bytes kirkwilliams2049 10 26,600 May-26-2025, 01:55 PM
Last Post: deanhystad
  is import cointegration_analysis a recognized module mitcht33 1 1,608 Nov-06-2023, 09:29 PM
Last Post: deanhystad
  problem in import module from other folder akbarza 5 17,797 Sep-01-2023, 07:48 AM
Last Post: Gribouillis
  can not import anaconda pandas module. PySpark pandas module is imported!! aupres 0 1,828 Aug-06-2023, 01:09 AM
Last Post: aupres
  Import a module one step back of the path prathampatel9 1 2,547 Sep-21-2022, 01:34 PM
Last Post: snippsat
  Cryptic Error with import statement Led_Zeppelin 2 4,431 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 14,215 Jan-04-2022, 01:05 PM
Last Post: Anldra12
  Import a module for use in type hint? Milosz 0 2,395 Nov-08-2021, 06:49 PM
Last Post: Milosz
  Can't install nor import delorean module Tek 3 5,289 Oct-27-2021, 03:32 AM
Last Post: Tek

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.