Installing Flask
Flask arrives through pip, the Python installer. One command adds it to Python.
The install command
This command installs Flask. Run it in a terminal.
pip install flaskThe version check
This code asks for the installed Flask version. The answer starts with 3.
from importlib.metadata import version
print(version("flask").split(".")[0])Example
from importlib.metadata import version
print(version("flask").split(".")[0])
print("Flask is installed")Key points
- Use pip install flask to install Flask.
- Pip runs at a terminal prompt.
- Pip does not run inside a Python file.
- A terminal takes typed commands for the computer.
- Check the install with a short version check in Python.
- Version numbers carry three parts, like 3.1.3.
In this example, version reads the installed Flask version. The opening print shows 3, the first part. The second print states the result: Flask is installed.
Note
If the check fails, Flask is missing, so install it once more.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
Which command installs Flask?