title: flask run does not work but python server.py does! Environment vars set
body: <p>When I try to run my very simple Flask application using <code>flask run</code> it does not work but when I <code>cd src</code> and <code>python server.py</code> it does work. </p>
  
  <p>File structure:</p>
  
  <pre><code>my_project
  |____init__.py
  |
  |__src
  |  |____init__.py
  |  |__server.py
  |  |__chat.py
  |
  |__test
  |  |____init__.py
  |  |__test_server.py
  |  |__test_chat.py
  |
  |__FLASK_ENV_VARS.sh
  </code></pre>
  
  <p><code>server.py</code></p>
  
  <pre><code>from flask import Flask, jsonify
  import chat
  
  api = Flask(__name__)
  
  
  @api.route('/')
  def root():
      message = chat.say_hello()
      return jsonify(message=message)
  
  
  if __name__ == '__main__':
      api.run(debug=True)
  </code></pre>
  
  <p>In order to get the tests to pass, I need to <code>from src import chat</code>. When I leave it as <code>import chat</code> the server runs when I try <code>python server.py</code> but not <code>flask run</code> (which doesn't run either way of importing chat). Interestingly, I get a red squggly line under chat from my IDE when <code>import chat</code> that goes away with <code>from src import chat</code>.</p>
  
  <p><code>test_server.py</code></p>
  
  <pre><code>import pytest
  
  
  from src.server import api
  
  
  def test_route(client):
      response = client.get('/')
      assert response.status_code == 200
      expected_data = b'{"message":"Welcome message here"}\n'
      assert response.data == expected_data
  
  
  
  @pytest.fixture
  def client():
      api.testing = True
      client = api.test_client()
      return client 
  </code></pre>
  
  <p>The content of the environment variables shell script is </p>
  
  <pre><code>export FLASK_ENV=development
  export FLASK_DEBUG=1
  export FLASK_APP=server.py
  </code></pre>
  
  <p>I have tried making <code>FLASK_APP</code> both <code>src.server.py</code> and <code>server.py</code>, neither currently works. Of course I remember to run the shell script and echo the variables to ensure that they have changed. </p>
  
  <p>The error I get from <code>flask run</code> is <code>flask.cli.NoAppException: Could not import "my_project.server".</code></p>
  
  <p>When I <code>cd src</code> and <code>flask run</code> I get <code>flask.cli.NoAppException: While importing "my_project.src.server", an ImportError was raised:</code></p>
  
  <p>The problem, I suspect lies with the way chat is imported. The tests only run with <code>from src import chat</code>. When I run <code>python server.py</code> I have to have only <code>import chat</code> or it doesn't work. I get <code>ModuleNotFoundError: No module named 'chat'</code> as part of the stack trace or <code>ModuleNotFoundError: No module named 'src'</code> depending on which style of import was used. I'm not sure what I am getting wrong here. I am inclined to think that <code>from src import chat</code> is correct since this is what makes the tests pass, however I can't get this to work at all. </p>