How to Install Flask: Step-by-Step Guide for Beginners
To install
Flask, open your terminal and run pip install flask. This command downloads and installs Flask and its dependencies so you can start building web apps.Syntax
The basic command to install Flask is simple and uses Python's package manager pip. Here is the syntax:
pip install flask: Installs the latest stable Flask version.pip install flask==x.y.z: Installs a specific Flask version.pip install --upgrade flask: Updates Flask to the latest version.
bash
pip install flask
Example
This example shows how to install Flask and verify the installation by checking its version.
bash
pip install flask
python -c "import flask; print(flask.__version__)"Output
2.3.2
Common Pitfalls
Some common mistakes when installing Flask include:
- Not using a virtual environment, which can cause package conflicts.
- Running
pipwithout the right Python version or permissions. - Typing
flaskwith uppercase in the install command (it should be lowercase).
Always activate a virtual environment before installing Flask to keep your project dependencies clean.
bash
python -m venv venv source venv/bin/activate # On Windows use: venv\Scripts\activate pip install flask
Quick Reference
Here is a quick summary to remember when installing Flask:
| Command | Purpose |
|---|---|
| pip install flask | Install latest Flask |
| pip install flask==x.y.z | Install specific Flask version |
| pip install --upgrade flask | Update Flask to latest |
| python -m venv venv | Create a virtual environment |
| source venv/bin/activate | Activate virtual environment (Linux/macOS) |
| venv\Scripts\activate | Activate virtual environment (Windows) |
Key Takeaways
Use
pip install flask to install Flask quickly and easily.Always use a virtual environment to avoid conflicts with other Python packages.
Check your Flask version with
python -c "import flask; print(flask.__version__)" after installation.Use lowercase
flask in the install command to avoid errors.Upgrade Flask anytime with
pip install --upgrade flask to get the latest features.