Forums

ModuleNotFoundError with factory create_app function

Hello,

I am trying to deploy my app to pythonanywhere but am getting the following error:

2023-04-03 18:21:12,857: Error running WSGI application
2023-04-03 18:21:12,858: ModuleNotFoundError: No module named 'flask_migrate'
2023-04-03 18:21:12,858:   File "/var/www/[username]_pythonanywhere_com_wsgi.py", line 111, in <module>
2023-04-03 18:21:12,858:     from app import create_app
2023-04-03 18:21:12,858: 
2023-04-03 18:21:12,858:   File "/home/[my-username]/[my-app-name]/app/__init__.py", line 2, in <module>
2023-04-03 18:21:12,858:     from flask_migrate import Migrate

Below my init.py file

from flask import Flask
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy

import config
from flask_login import LoginManager

db = SQLAlchemy()
login = LoginManager()
login.login_view = 'main.login'
migrate = Migrate()


def create_app(config_class=config.config['development']):
    app = Flask(__name__)
    app.config.from_object(config_class)
    db.init_app(app)
    login.init_app(app)
    migrate.init_app(app, db)

    from app.main import bp as main_bp
    app.register_blueprint(main_bp)

    return app

from app import models

i've added below lines to the wsgi file:

from app import create_app
application = create_app()

This resolved any issues for most people online but i keep seeing the same issue.

The application works locally on pycharm running "flask run"

Can you assist?

Never mind, I figured out that I did not have the venv active when installing the packages. So i reinstalled the packages with the virtual environment active and it works now