0

I don't think it's a circular dependent import issue.

This is what my file hierarchy looks like

This is what my file hierarchy looks like

The code for run.py is

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

The beginning of 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

The command I run in the bash shell is

 python3 run.py 

And what I get is

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)
Ken Ryan
  • 23
  • 5
  • error shows that you have installed other module with name `site` and it can't find `app` in this module. – furas Aug 06 '19 at 02:54
  • you have to put `run.py` in folder `website` and then it will see subfolder `site` and `from site...` should work. Or rename `__init__.py` to something different and import `from something_different`. Web page is rathe a application than module (which use `__init__.py`) – furas Aug 06 '19 at 03:02
  • Thanks for pointing that out to me @furas, that was the issue. – Ken Ryan Aug 06 '19 at 03:13

1 Answers1

0

There already exists a module named site so I had to change the name of my folder/module.

Ken Ryan
  • 23
  • 5