siva
siva

Reputation: 1513

Python ModuleNotFoundError during gunicorn start

I want to start gunicorn with >> gunicorn wsgi:app.
But I get an error saying ModuleNotFoundError: No module named 'default_config. My virtuel env is activated. I spent hours on google but couldn't find an answer. Even hints are very much appreciated.

Folder structure:

 - App
   - flask_app
   - __init__.py
   - factory.py
   - default_config.py
- venv (virtual environment)
- wsgi.py

__init__.py => is empty

### wsgi.py ###
from flask_app.factory import create_app
app = create_app('development')

.

### default_config.py ###
import os

basedir = os.path.abspath(os.path.dirname(__file__))

class Config:
    SECRET_KEY = 'development key'

class DevelopmentConfig(Config):
    DEBUG = True

class ProductionConfig(Config):
    DEBUG = False

config = {
    'development': DevelopmentConfig,
    'production': ProductionConfig,
    'default': DevelopmentConfig
    }

.

### factory.py ###
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from default_config import config

db = SQLAlchemy()

def create_app(config_name):
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_object(config[config_name])
    app.config.from_pyfile('config.py')

    db.init_app(app)
    return app

Upvotes: 5

Views: 2572

Answers (1)

mohammad
mohammad

Reputation: 2198

This is because your wsgi file doesn't know the app location by default. You can use relative path like the comment above or you can just add app to your environment path.

Upvotes: 3

Related Questions