1

I am trying to import Bootstrap5 from flask_bootstrap in my Python code on a Mac M1 using Python3. However, I get an import error saying that the name Bootstrap5 cannot be imported from flask_bootstrap. Here's the code snippet:

 from flask import Flask, flash, jsonify

 from flask_bootstrap import Bootstrap5

and I get this error

cannot import name 'Bootstrap5' from 'flask_bootstrap'

I can import bootstrap without any issues, but not Bootstrap5. What could be causing this problem and how can I fix it?

  • I am having the same error message after I deploy on a cloud server - but I do not get the error on my Mac when I test locally using the development server (using a virtual environment locally) – macloo Apr 15 '23 at 16:22

3 Answers3

1

follow the instructions on https://bootstrap-flask.readthedocs.io/en/stable/basic/#installation

pip uninstall flask-bootstrap bootstrap-flask
pip install bootstrap-flask
0

I've found the fix! In your requirements.txt, manually delete the line:

Flask-Bootstrap4==4.0.2

Yes, Bootstrap-Flask does need this, but it will install it on its own. Removing that line and re-uploading requirements.txt to the cloud server solved this issue for me.

macloo
  • 627
  • 1
  • 9
  • 19
-1

According to Bootstrap documentation, basic usage

from flask import Flask
from flask_bootstrap import Bootstrap

def create_app():
  app = Flask(__name__)
  Bootstrap(app)

  return app

# do something with app...

Import Bootstrap instead if Bootstrap5

mrkgbr
  • 1
  • 1