Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

Installing Flask via pip in Flask


Flask is a lightweight and flexible web framework for Python. In this article, we will explain step-by-step how to install Flask using pip, Python's package manager, with a real example.

Step 1: Verify Python Installation

Ensure Python is installed on your system. Open a terminal or command prompt and run:

            python --version
        

If Python is not installed, download it from https://www.python.org/ and follow the installation instructions.

Step 2: Install pip

pip is Python's package manager and is often included with Python installations. To check if pip is installed, run:

            pip --version
        

If pip is not installed, you can install it by following the instructions at pip's official site.

Step 3: Set Up a Project Directory

Create a new directory for your Flask project. For example:

            mkdir flask_example
            cd flask_example
        

Step 4: Install Flask Using pip

In your terminal, install Flask by running:

            pip install flask
        

After installation, you can verify the Flask version by running:

            flask --version
        

This ensures Flask has been installed successfully.

Step 5: Create a Simple Flask Application

Create a new Python file named app.py in your project directory. Add the following code:

            from flask import Flask
            app = Flask(__name__)

            @app.route("/")
            def home():
                return "Hello, Flask!"

            if __name__ == "__main__":
                app.run(debug=True)
        

This is a simple Flask application that responds with "Hello, Flask!" when accessed at the root URL.

Step 6: Run the Flask Application

To start the Flask application, run the following command in your terminal from the project directory:

            python app.py
        

The application will start, and you can open your browser and visit http://127.0.0.1:5000/ to see the output.

Conclusion

You have successfully installed Flask using pip and created a simple Flask application. This forms the foundation for developing web applications with Flask.

Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java