简体   繁体   English

Python:ImportError:无法导入名为的模块

[英]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.

相关问题 WSGI、Flask、Python 2.7、Apache2、ImportError = 没有名为 Flask 的模块 - WSGI, Flask, Python 2.7, Apache2, ImportError = no modul named flask 导入错误:无法导入测试模块 - ImportError: Failed to import test modul 无法将请求导入 Python:ImportError 没有名为 urllib3 的模块 - Can't Import Requests into Python: ImportError no module named urllib3 在 Python 中导入本地模块 - ImportError: Not module named * - Import a local module in Python - ImportError: Not module named * Python无法导入,ImportError:未命名模块 - Python cannot import, ImportError: No module named Python - 导入请求 ImportError: No module named requests - Python - import requests ImportError: No module named requests Python - 导入 tweepy 导入错误:没有名为 tweepy 的模块 - Python - Import tweepy ImportError: No module named tweepy 无法导入模块-ImportError:未命名模块 - Can't import modules - ImportError: No module named 我的新virtualenv获取ImportError:没有名为bz2的模块,但系统python可以导入 - My new virtualenv gets ImportError: No module named bz2 but system python can import 安装后,Python + RaspberryPI无法导入GPIO:ImportError:没有名为_GPIO的模块 - Python + RaspberryPI can't import GPIO after installing: ImportError: No module named _GPIO
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM