How to Install Python Flask App in your Computer (Windows or Linux)

If you want to install flask app in your computer for web development using Python you can follow the tutorial.

To start, let’s create a simple “hello world” application. First, create a new project. From the terminal or command line create a new directory:
1.  mkdir myflaskwebsite

2. cd myflaskwebsite

Remember, you can change the name of your project as per your requirement.

Inside the project directory, create a virtual environment for the project. You can check virtualenv for more information. First, install virtualenv, create one, activate it, and install Flask:
1. pip install virtualenv

#Create virtualenv linux

2. python3 -m venv venv

#Create virtualenv for windows

3. py -3 -m venv venv

#Activate virualenv linux

4 . venv/bin/activate

#Activate virualenv for windows

5. venv\Scripts\activate

#Install Flask on the enviroment

6. pip install flask

Now create a file main.py in your directory created earlier

from flask import Flask

app = Flask(__name__)

@app.route(‘/’)
def hello():
      return “Hello World!”

Now run these commands in terminal or cmd

#Tell the terminal what application to run
export FLASK_APP=main.py
#Tell the terminal what application to run for windows
set FLASK_APP=main.py
#Run the application
flask run

If everything is fine you will be able to see your application on this url

127.0.0.1:5000

You can open this url from any browser.

Now Deploy Flask App to Heroku

Step-9: Deploy your app to heroku

% heroku login
% git init
% heroku git:remote -a my-python-app
% git add.
% git commit -am "First python app"
% git push heroku master

Leave a Comment