title: Flask debug mode gives an "OSError: [Errno 8] Exec format error" when running using python
body: <p>So, here's a file I made (flaskblog.py):</p>
  
  <pre class="lang-py prettyprint-override"><code>from flask import Flask
  app = Flask(__name__)
  
  @app.route("/")
  def hello():
      return "&lt;h1&gt;Home Page&lt;/h1&gt;"
  </code></pre>
  
  <p>Here's how I first ran it:</p>
  
  <pre><code>$ export FLASK_APP=flaskblog.py
  $ flask run
  </code></pre>
  
  <p>Here's how I ran it in debug mode:</p>
  
  <pre><code>$ export FLASK_APP=flaskblog.py
  $ export FLASK_DEBUG=1
  $ flask run
  </code></pre>
  
  <p>Now I want to run the application directly using python. I first updated the .py file:</p>
  
  <pre class="lang-py prettyprint-override"><code>from flask import Flask
  app = Flask(__name__)
  
  @app.route("/")
  def hello():
      return "&lt;h1&gt;Home Page&lt;/h1&gt;"
  
  if __name__ == "__main__":
      app.run()
  </code></pre>
  
  <p>This is the command I used to run the python file:</p>
  
  <pre><code>$ python3 flaskblog.py
  </code></pre>
  
  <p>It worked fine. Now I want to run the application in debug mode. So, I updated the file:</p>
  
  <pre class="lang-py prettyprint-override"><code>from flask import Flask
  app = Flask(__name__)
  
  @app.route("/")
  def hello():
      return "&lt;h1&gt;Home Page&lt;/h1&gt;"
  
  if __name__ == "__main__":
      app.run(debug=True) #Added ("debug=True") here
  </code></pre>
  
  <p>Command used to run the file:</p>
  
  <pre><code>$ python3 flaskblog.py
  </code></pre>
  
  <p>Here's the error:</p>
  
  <pre><code> * Serving Flask app "flaskblog" (lazy loading)
   * Environment: production
     WARNING: Do not use the development server in a production environment.
     Use a production WSGI server instead.
   * Debug mode: on
   * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
   * Restarting with stat
  Traceback (most recent call last):
    File "flaskblog.py", line 9, in &lt;module&gt;
      app.run(debug=True)
    File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 943, in run
      run_simple(host, port, self, **options)
    File "/usr/local/lib/python3.6/dist-packages/werkzeug/serving.py", line 988, in run_simple
      run_with_reloader(inner, extra_files, reloader_interval, reloader_type)
    File "/usr/local/lib/python3.6/dist-packages/werkzeug/_reloader.py", line 332, in run_with_reloader
      sys.exit(reloader.restart_with_reloader())
    File "/usr/local/lib/python3.6/dist-packages/werkzeug/_reloader.py", line 176, in restart_with_reloader
      exit_code = subprocess.call(args, env=new_environ, close_fds=False)
    File "/usr/lib/python3.6/subprocess.py", line 267, in call
      with Popen(*popenargs, **kwargs) as p:
    File "/usr/lib/python3.6/subprocess.py", line 709, in __init__
      restore_signals, start_new_session)
    File "/usr/lib/python3.6/subprocess.py", line 1344, in _execute_child
      raise child_exception_type(errno_num, err_msg, err_filename)
  OSError: [Errno 8] Exec format error: '/XXX/XXX/XXX/XXX/XXX/XXX/XXX/XXX/Flask_Blog/flaskblog.py'
  
  </code></pre>
  
  <p>I just used "XXX" instead of the actual directories. Any help will be appreciated!</p>
  
  <p>PS: All the code is from this video: <a href="https://www.youtube.com/watch?v=MwZwr5Tvyxo&amp;list=PL-osiE80TeTs4UjLw5MM6OjgkjFeUxCYH" rel="noreferrer">https://www.youtube.com/watch?v=MwZwr5Tvyxo&amp;list=PL-osiE80TeTs4UjLw5MM6OjgkjFeUxCYH</a></p>