Skip to main content

Installing Flask

Introduction

Flask is a popular and lightweight web framework for Python. It's perfect for beginners and is a great way to start your journey with Python web development. In this tutorial, we will be walking you through the process of installing Flask in your local development environment.

Prerequisites

Before you start the installation, you will need the following:

  • A computer running on Linux, macOS, or Windows.
  • Python installed (version 3.6 or newer is recommended).
  • pip, the Python package installer.

You can check if you have Python and pip installed by opening your terminal or command prompt and typing:

python --version
pip --version

If Python and pip are installed correctly, you should see the version of the Python and pip that you have installed.

Installing Flask

The process of installing Flask involves just a few steps:

Step 1: Set up a Virtual Environment

A virtual environment is a tool that helps to keep dependencies required by different projects separate by creating isolated Python virtual environments for them. This is one of the best practices in Python programming.

You can create a virtual environment in your project directory using the venv module.

Open your terminal or command prompt, navigate to your project directory, and enter the following command:

python -m venv myenv

This will create a new virtual environment named myenv in your project directory.

Step 2: Activate the Virtual Environment

Before you can start installing Flask, you need to activate the virtual environment that you have just created. The command to activate the virtual environment varies depending on your operating system.

On macOS and Linux:

source myenv/bin/activate

On Windows:

.\myenv\Scripts\activate

Once the virtual environment is activated, your terminal or command prompt should indicate that you are now working inside the virtual environment.

Step 3: Install Flask

Now that you've activated your virtual environment, you can install Flask using pip. Enter the following command in your terminal:

pip install flask

This command tells pip to download and install Flask from the Python Package Index (PyPI).

After the installation is complete, you can confirm that Flask is installed by showing its version with:

flask --version

You should see the version of Flask that you've installed.

Conclusion

Congratulations, you have successfully installed Flask in your local environment! You are now ready to start building your first web application with Flask. In the next tutorials, we will guide you through creating a simple Flask application.