尝试从同一包导入时,出现了ImportError

时间:2019-08-06 02:45:03

标签: python python-3.x flask

我认为这不是循环依赖的进口问题。

这就是我的文件层次结构

This is what my file hierarchy looks like

run.py 的代码是

from site import app

if __name__ == "__main__":
app.run()

__ init.py __

from flask import Flask
from flask import Flask
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config['SECRET_KEY'] = '84e0621dd931baa7e6a014901c6183d5'
#sqllite is for development purposes
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
db = SQLAlchemy(app)

from site import routes

routes.py

的开头
from flask import render_template, url_for, flash, redirect
from site import app
from site.forms import RegistrationForm, LoginForm
from site.models import User, Campaign

我在bash shell中运行的命令是

 python3 run.py 

我得到的是

Traceback (most recent call last):
  File "run.py", line 1, in <module>
    from site import app
ImportError: cannot import name 'app' from 'site' (/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site.py)

1 个答案:

答案 0 :(得分:0)

已经存在一个名为site的模块,因此我不得不更改文件夹/模块的名称。