Hello guys i am trying to create a simple project with flask and it is my first time using init .py file. The tree structure is like this
FlaskApi/venv
├── lib64 -> lib
├── flaskapi
│ ├── generate_dummy_data.py
│ └── models.py
| └── routes.py
│ └── __init__.py
└── linked_list.py
│ └── sqlitedb.db
├── pyvenv.cfg
└── run.py
My generate_dummy_data.py file import is like this:
from flaskapi import db
from flaskapi.models import User, BlogPost
My init .py file is like this:
from flask import Flask
from sqlite3 import Connection as SQLite3Connection
from sqlalchemy import event
from sqlalchemy.engine import Engine
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///sqlitedb.db"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = 0
db = SQLAlchemy(app)
My models.py file is like this:
from flaskapi import db
from datetime import datetime
When i try to run the file generate_dummy_data.file i get this error:
ModuleNotFoundError: No module named 'flaskapi'
Can someone pls explain to me why this is happening? Thank you guys for your time
Since you're running generate_dummy_data.py
from the command line, you should move it out of the flaskapi folder (to the same level as the run.py script). Ie:
FlaskApi/venv
├── lib64 -> lib
├── flaskapi
| |
│ └── models.py
| └── routes.py
│ └── __init__.py
└── linked_list.py
│ └── sqlitedb.db
├── pyvenv.cfg
└── run.py
|--- generate_dummy_data.py <- should be here
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.