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?
To run the app outside of the VS Code debugger, use the following steps from a terminal: Set an environment variable for FLASK_APP . On Linux and macOS, use export set FLASK_APP=webapp ; on Windows use set FLASK_APP=webapp . Navigate into the hello_app folder, then launch the program using python -m flask run .
Flask is a web framework, it's a Python module that lets you develop web applications easily. It's has a small and easy-to-extend core: it's a microframework that doesn't include an ORM (Object Relational Manager) or such features. It does have many cool features like url routing, template engine.
You don't have installed flask
Install flask
as global package:
sudo pip install flask
Install in virtualenv
virtualenv venv source venv pip install flask
Install system package
debian, ubuntu
apt-get install python-flask
arch
pacman -S python-flask
fedora
yum install python-flask
Install via Anaconda
conda install flask
python -m pip install flask
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With