Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I'm trying to use flask and python. I did a simple file named
hello.py
. tHis file contains this code:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def main():
return "Welcome!"
if __name__ == "__main__":
app.run()
This is a simple hello world with flask. I want to execute it but actually, I have a problem. In the terminal, I typed python hello.py
and I get this error:
File "hello.py", line 1, in <module>
from flask import Flask
ImportError: No module named flask
Even that I installed flask globally.
I understand that this is a basic question, but I'm stuck?
–
–
–
Make sure that you entered the correct entry into the requirements.txt file. It should not be blank.
enter Flask==2.0.0 into the requirements.txt file.
–
pip install flask
Still you are having the same error then you have more than one version of python installed in your machine. So better to create a virtual environment for your app and install all package in it. For that install virtual environment.
py -m pip install --user virtualenv
Activate your venv
by
.\venv\Scripts\activate.bat
Now try to install flask in the venv
python -m virtualenv venv
if you install the flask and still get the error. Then, You should activate the source by following:
source env/bin/activate
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.