Paul
Paul

Reputation: 412

Gunicorn throws ModuleNotFound for some (but not all) flask modules

I have a basic flask app with this structure:

/
├── app.py
├── models.py
├── venv
│   ├── bin
│   └── ...

And app.py has these imports:

from flask import (
  Flask,
  g,
  render_template,
  flash,
  redirect,
  url_for,
  abort,
  jsonify
)
from flask_cors import CORS
from flask_login import (
  LoginManager,
  login_user,
  logout_user,
  login_required,
  current_user
)
from flask_bcrypt import check_password_hash
from flask_expects_json import expects_json
from flask_jwt_extended import (
  JWTManager, 
  create_access_token, 
  create_refresh_token, 
  fresh_jwt_required,
  jwt_refresh_token_required, 
  get_jwt_identity, 
  get_raw_jwt
)

I'm trying to start the app with gunicorn app:app, but I get ModuleNotFoundError: No module named 'flask_bcrypt' when I do.

All of the modules are in fact installed and I can run the app with python3 app.py just fine. If I move the from flask_bcrypt... line to the bottom, I get the same error for flask_expects_json and then flask_jwt_extended.

I don't understand why this is happening and I especially don't understand why flask, flask_cors, and flask_login don't give this error.

Any help is greatly appreciated; thank you.

Upvotes: 1

Views: 114

Answers (2)

Paul
Paul

Reputation: 412

I forgot to activate my virtualenv 😂

Thanks, no sleep! It actually works fine

Upvotes: 1

Ishan Joshi
Ishan Joshi

Reputation: 525

Have you tried importing flask_bcrypt as from flask.ext.bcrypt import check_password_hash

Upvotes: 0

Related Questions