ModuleNotFoundError: No module named 'flask_bootstrap'

Viewed 10157

I'm working on my very very first python program/assignment, I'm new to not just the language but it's also my first time outside of languages like Java, C#, and .Net, so I'm having a difficult time picking it up.

I was given a bunch of example files and am supposed to run them to get a feel for what I need to do, except I get an error: ModuleNotFoundError: No module named 'flask_bootstrap'

I ran my bin/activate successfully and here's a bit of command line:

(p3) C:\Users\ritol\OneDrive\School\Project Files\Project Files\Flask\2f>python weather.py Traceback (most recent call last): File "weather.py", line 2, in from flask_bootstrap import Bootstrap ModuleNotFoundError: No module named 'flask_bootstrap'

(p3) C:\Users\ritol\OneDrive\School\Project Files\Project Files\Flask\2f>bin/activate 'bin' is not recognized as an internal or external command, operable program or batch file.

Here's a list of pip installs I was given to do, and it did them:

Flask==1.1.1
Flask-Bootstrap==3.3.7.1
Flask-Login==0.4.1
flask-marshmallow==0.10.1
Flask-Migrate==2.5.2
Flask-RESTful==0.3.7
Flask-Script==2.0.6
Flask-SQLAlchemy==2.4.0
Flask-Testing==0.7.1
Flask-WTF==0.14.2
itsdangerous==1.1.0
Jinja2==2.10.1

2f/weather.py:

from flask import Flask, render_template
from flask_bootstrap import Bootstrap
app = Flask(__name__)
bootstrap = Bootstrap(app)


@app.route('/')
def index():

etc...

I expect to get it to show something like a previous example did:

 * Serving Flask app "FlaskApp" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 173-453-384
 * Running on http://127.0.0.1:5001/ (Press CTRL+C to quit)

instead I get

Traceback (most recent call last):
  File "weather.py", line 2, in <module>
    from flask_bootstrap import Bootstrap
ModuleNotFoundError: No module named 'flask_bootstrap'
3 Answers

I had the same issue.

deactivate and activate the virtual environment solved it

deactivate
. venv/bin/activate

While I waited for help, I was trying to figure out if I could get the virtual environment to be 'hooked up' to pycharm, and I found that pycharm made it's own virtual environment without the pip installs I was given, so I got the command line open into that, ran the pip installs, and now I can get it to run through pycharm.

So it works in the virtual environment that I discovered and added the installs to. (did not work from pycharm at all due to pycharm didn't know flask was installed and would error sooner) But not in the one that I was instructed on making. I don't know why.

You have to install flask_bootstrap using the following command:

pip install flask_bootstrap

In your case, you should not use a hyphen(-) In place of hyphen use underscore( _) then it might work.

Related