.
├── app.py
├── README.md
└── requirements.txt
Make sure you have python3 installed in your machine before you continue. For windows users, the path to python3 must be added to the system environment variable PATH.
pip3 install virtualenv
$ virtualenv -p python3 venvThis will create a virtual environment named venv with python3 as its interpreter.
If you have multiple versions of python installed and added to PATH, find out the path for python3.
> where python
C:\Python27\python.exe
C:\Users\deepd\AppData\Local\Programs\Python\Python37-32\python.exe
C:\Users\deepd\AppData\Local\Programs\Python\Python36\python.exeYou will get an output of all the python execuables that are added to PATH. For example I have python2.7, python3.6 and python3.7 installed.
In this command, the path to python3.6 is being used to create the virtual environment.
> virtualenv -p C:\Users\deepd\AppData\Local\Programs\Python\Python36\python.exe venv$ source venv/bin/activate
(venv) ...$ > venv\Scripts\activate
(venv) ...> You can install the requirements for this project from the requirements.txt file by using the command
(venv) ...$ pip install -r requirements.txt
Since you're inside a virtualenv, the requirements will be installed inside it, keeping the project requirements specific to the project.
Run the app.py file to start the app server.
(venv) ...$ python app.py
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 249-131-684
or
(venv) ...$ flask run
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Open up a web browser and navigate to
http://127.0.0.1:5000/hello
Or, click here to do the same.