Set up env (virtual environment)
$ python -m venv env # Windows
$ python3 -m venv env # Linux or macOS
In python, there is no central lib management tools like Maven in Java, and it is not possible to have different version of same lib, so we need to create a env to manage the lib we use in this project
now we created the env, we need to activate it
$ source env/bin/activate # Linux or macOS
$ .\env\Scripts\activate # Windows
if you successfully activated the env, you will see the env name in the terminal
(env) $
if you want to deactivate the env, just type deactivate
in the terminal
Install Flask
$ pip install Flask
$ pip install flask==2.1.3 # install specific version
Create a simple Flask app
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
save the code above to a file named app.py
, and run the app
$ export FLASK_APP=app.py # Linux or macOS
> $env:FLASK_APP = "hello.py" # Windows
$ flask run