title: How can I run this flask app using gunicorn
body: <p>I Refactored my code after making it which turns out to be a mistake and now I am not able to get it run using gunicorn. If you have advice for structuring or factoring from here on then that's welcome too.
  I am trying to get it run from 5 days now, Struggling a lot.</p>
  
  <p>Directory Structure</p>
  
  <pre><code>app--
       --db.sqlite
       --__init__.py
       --models.py
       --MyFunctions.py
       --routes.py
       --schemas.py
       --sockets.py
  app.py
  </code></pre>
  
  <p>Inside app.py</p>
  
  <pre><code>from app import *
  
  
  from app.MyFunctions import *
  from app.models import *
  from app.schemas import *
  from app.routes import *
  from app.sockets import *
  
  
  port=os.environ.get("PORT")
  
  if port is None or port == "":
      port = 3000
  
  if __name__ == '__main__':
      socketio.run(app, host='0.0.0.0', port=port) # when running on heroku
  </code></pre>
  
  <p>Inside <strong>init</strong>.py</p>
  
  <pre><code>import jwt
  from flask import (
      Flask,
      request,
      jsonify,
      make_response,
  )
  from flask_socketio import (
      SocketIO, 
      send, 
      emit, 
      join_room, 
      leave_room,
  )
  from sqlalchemy import (
      Column,
      Integer,
      String,
      Boolean,
      ForeignKey,
      DateTime,
      Sequence,
      Float,
  )
  from flask_sqlalchemy import SQLAlchemy
  from flask_marshmallow import Marshmallow
  from os import environ
  
  
  def debug(msg):
      print('\n\n\n'+str(msg)+'\n\n\n'+'\n\nType:\t'+str(type(msg))+'\n\n')
  
  from .models import *
  socketio = SocketIO(app, cors_allowed_origins='*')
  </code></pre>
  
  <p>Inside models.py (only import related things not models, my most of the imports are lying here only)</p>
  
  <pre><code>from flask import (
      Flask,
      request,
      jsonify,
      make_response,
      redirect,
  )
  from flask_socketio import (
      SocketIO, 
      send, 
      emit, 
      join_room, 
      leave_room,
  )
  from sqlalchemy import (
      Column,
      Integer,
      String,
      Boolean,
      ForeignKey,
      DateTime,
      Sequence,
      Float,
  )
  from flask_sqlalchemy import SQLAlchemy
  from flask_marshmallow import Marshmallow
  from flask_bcrypt import Bcrypt
  from os import environ
  from flask_cors import CORS, cross_origin
  
  
  
  app = Flask(__name__)
  root = os.path.dirname(os.path.abspath(__file__))
  CORS(app, support_credentials=True)
  basedir = os.path.abspath(os.path.dirname(__file__))
  
  PG = os.environ.get("DATABASE_URL")
  
  if PG is None or PG=="":
      app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
          os.path.join(basedir, 'db.sqlite')
  else:
      app.config['SQLALCHEMY_DATABASE_URI'] = PG
  
  
  app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
  app.config['SECRET_KEY'] = environ.get('STRIPE_API_KEY')
  
  
  db = SQLAlchemy(app)
  
  ma = Marshmallow(app)
  
  bcrypt = Bcrypt(app)
  
  socketio = SocketIO(app, cors_allowed_origins='*')
  </code></pre>
  
  <p>edit:
  Currently I am using python only to run the app on heroku so my Procfile looks like</p>
  
  <pre><code>web: python app.py
  </code></pre>
  
  <p>And yes I have tried many other formats like</p>
  
  <pre><code>web: gunicorn app:app
  web: gunicorn models:app
  web: gunicorn app/models:app
  </code></pre>
  
  <p>Tried by making different run file also and many other methods
  I am afraid that I need to change it's structure to make it work.</p>