How To Fix “ImportError: No module named flask”?
Are you having problems with the issue “ImportError: No module named flask“? How to fix it? In today’s article, I will provide solutions for you to solve the issues. Please follow the below steps to get the problem resolved now
How did “ImportError: No module named flask” occur?
ImportError: No module named flask
When you work with Python, you may get the issue ImportError: No module named flask. Don’t worry, we are here to provide you solutions in order to resolve your problem.
How to fix “ImportError: No module named flask”?
To Solve ImportError: No module named flask Error If You are using python 3.X version then all you need to do is just install flas module with this command: pip3 install flask. This command will create a virtualenv. Next, open it with cd flask. Now you have to activate the virtualenv with this command: source bin/activate. Install flask now: pip install flask Your error must now be fixed.
Solution 1: Python 3.X
If you are using Python 3.X version, then all that is required is to install flas module with the following command.
pip3 install flask
Solution 2: Working with the environment
First, create a virtualenv using this command.
virtualenv flask
Next, open it.
cd flask
This command will activate virtualenv.
source bin/activate
Now, install the flask.
pip install flask
Create a new file called helloWorld.py
. Add the code below to it.
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()
Run it with:
python helloWorld.py
Final words
The above are useful solutions that can help you fix “ImportError: No module named flask” problem, if you can’t solve it well. Please leave a message.