[英]Python: ImportError : Can not import modul named
i'm working with python 3.7 and I try to develop an ecommerce api with flask and many other flask extension but when i want to initiate for example my migration to create databse i got an import error I have a such great problem with import in python that i always get frustrated with that, is someone can tell what i dit wrong? i'm working with python 3.7 and I try to develop an ecommerce api with flask and many other flask extension but when i want to initiate for example my migration to create databse i got an import error I have a such great problem with import in python我总是对此感到沮丧,有人能说出我做错了什么吗? I put below the architecture of my root directory and the factory.py file where in i tried to import some variables我把我的根目录的架构和 factory.py 文件放在我试图导入一些变量的地方
and I put below the stack trace i got when I try to run python shared/manage.py
我把当我尝试运行python shared/manage.py
时得到的堆栈跟踪放在下面
Traceback (most recent call last):
File "shared/manage.py", line 1, in <module>
from factory import create_app
ImportError: No module named factory
I this is my factory.py file我这是我的 factory.py 文件
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_mail import Mail
from config import Config
from flask_bcrypt import Bcrypt
from flask_cors import CORS
from flask_migrate import Migrate
import os
db = SQLAlchemy()
mail = Mail()
bcrypt = Bcrypt()
cors = CORS()
migrate = Migrate()
def create_app():
app = Flask(__name__, root_path=os.getcwd())
app.config.from_object(Config)
db.init_app(app)
mail.init_app(app)
cors.init_app(app)
migrate.init_app(app, db)
from admin.views import admin
from users.views import users
from orders.views import order
from products.views import product
from main.views import main
from adresses.views import adresse
from comments.views import comment
from car.views import carmanager
from categories.views import category
from quote.views import quote
from message.views import message
from wishlist.views import wishlist
with app.app_context():
app.register_blueprint(admin)
app.register_blueprint(order)
app.register_blueprint(users)
app.register_blueprint(product)
app.register_blueprint(main)
app.register_blueprint(adresse)
app.register_blueprint(comment)
app.register_blueprint(carmanager)
app.register_blueprint(category)
app.register_blueprint(quote)
app.register_blueprint(message)
app.register_blueprint(wishlist)
return app
if someone can help it will be very helpful如果有人可以提供帮助,那将非常有帮助
The problem does not lie in factory.py
.问题不在于factory.py
。 You are trying to import a file one level higher in the directory tree.您正在尝试在目录树中导入更高一级的文件。 As such, your import statement should be:因此,您的导入语句应该是:
from ..factory import create_app
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.