title: Flask: cannot import name 'app'
body: <p>Trying to run my python file <code>updater.py</code> to SSH to a server and run some commands every few set intervals or so. I'm using APScheduler to run the function <code>update_printer()</code> from <code>__init__.py</code>. Initially I got a <code>working outside of application context error</code> but someone suggested that I just import app from <code>__init__</code>.py. However it isn't working out so well. I keep getting a <code>cannot import name 'app'</code> error.</p>
  
  <p><strong>app.py</strong></p>
  
  <pre><code>from queue_app import app
  
  if __name__ == '__main__':
      app.run(debug=True)
  </code></pre>
  
  <p><strong>__init__.py</strong></p>
  
  <pre><code>from flask import Flask, render_template
  from apscheduler.schedulers.background import BackgroundScheduler
  from queue_app.updater import update_printer
  app = Flask(__name__)
  app.config.from_object('config')
  
  @app.before_first_request
  def init():
      sched = BackgroundScheduler()
      sched.start()
      sched.add_job(update_printer, 'interval', seconds=10)
  
  @app.route('/')
  def index():
      return render_template('index.html')
  </code></pre>
  
  <p><strong>updater.py</strong></p>
  
  <pre><code>import paramiko
  import json
  from queue_app import app
  
  def update_printer():
      ssh = paramiko.SSHClient()
      ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
      ssh.connect(app.config['SSH_SERVER'], username = app.config['SSH_USERNAME'], password = app.config['SSH_PASSWORD'])
  
  ...
  </code></pre>
  
  <p><strong>File Structure</strong></p>
  
  <pre><code>queue/
     app.py
     config.py
     queue_app/
        __init__.py
        updater.py
  </code></pre>
  
  <p><strong>Error</strong></p>
  
  <pre><code>Traceback (most recent call last):
    File "app.py", line 1, in &lt;module&gt;
      from queue_app import app
    File "/Users/name/queue/queue_app/__init__.py", line 3, in &lt;module&gt;
      from queue_app.updater import update_printer
    File "/Users/name/queue/queue_app/updater.py", line 3, in &lt;module&gt;
      from queue_app import app
  ImportError: cannot import name 'app'
  </code></pre>
  
  <p>What do I need to do be able to get to the app.config from updater.py and avoid a "working outside of application context error" if ran from APScheduler?</p>