I have a directory setup as follows:
/directory
/directory/__init__.py
/directory/setup.py
/directory/app/db.py
/directory/app/__init__.py
The /directory/__init__.py file contains the line "import app" which then fails in /directory/app/__init__.py due to the line "import db" when I try to run the setup.py file.
HOWEVER, if I change the error line to "from app import db" then it works fine. Why is this? I'm guessing it has to do with the fact I run it from a parent directory. Is there any way to make this work? Or do I just change all of the imports to "from app import x" even when it's being called from the app folder?
Thanks for any clarification.
Edit: Here's the error:
Traceback (most recent call last):
File "setup.py", line 2, in <module>
import app
File "/directory/app/__init__.py", line 1, in <module>
import db
ImportError: No module named 'db'
Edit2: Here's the /directory/app/__init__.py file (/directory/__init__.py is empty)
import db
from flask import Flask, render_template
DEBUG = True
app = Flask(__name__)
app.config.from_object(__name__)
@app.route("/")
def hello():
return render_template()
def run(host, port):
db.init_db()
app.run(host=host, port=port)
Final Edit: I had rephrased my question here and was given the right answer. I wasn't sure if the python3 change was relevant. Thanks!
__init__.pyfiles and at least the first two lines ofsetup.py?