mar5us
Student - Technical Writing
Lesson 4
Screen 1 of 16
1) Components of a Web application
2) Web frameworks and Flask
3) Installing Python and packages
4) Creating your development environment
5) Building your first local Flask app
6) Running your first Flask app
7) Web application deployment
8) Deploying to PythonAnywhere
Lesson 4
Screen 2 of 16
Lesson 4
Screen 3 of 16
A development environment is virtual space on your local computer which contains the software tools and technologies you use to build your application.
You have installed Python to create your first Flask app. You will also need to install packages (like Flask) and a place to store your application's files, as you create them.
Your development environment can hold your files, packages and other tools. This will help organise your first Flask app project and keep it seperated from other projects, as well as your local system files.
Lesson 4
Screen 4 of 16
There is no correct way to arrange a Flask Web application development environment.
Most applications/ projects are contained in a top level directory (i.e. the project's 'root directory').
Lesson 4
Screen 5 of 16
c:\~\myproject\
For clarity, we will refer to your new root directory as having the path shown below:
Your new root directory contains your development environment. You will install packages and other tools into your development environment during this lesson.
Lesson 4
Screen 6 of 16
c:\~\myproject\app
First, you need a directory for your Flask application files.
Next, you need a special directory called a 'virtual environment' inside your root directory.
A virtual environment is an isolated working copy of Python which allows you to work on a specific project without affecting other projects
Lesson 4
Screen 7 of 16
Lesson 4
Screen 8 of 16
Virtual environments:
Step 1. Installation
You will install the virtualenv package into your project's root directory using the pip package manager
Lesson 4
Screen 9 or 16
Step 3. Activation
You will activate your new VE and verify its activation
Step 2. Creation
You will use the virtualenv package to create a new virtual environment (VE) inside your project's root directory
next we will guide you through each step
To install the virtualenv package with pip:
1. Open a command prompt (cmd)
type cmd into windows search and press return
select the cmd launcher icon to open cmd
Lesson 4
Screen 10 of 16
next we will create the virtual environment
pip install virtualenv
2. Type the following into cmd, then press return
select the cmd launcher icon to open cmd
To create a virtual environment:
Lesson 4
Screen 11 of 16
next we will activate the virtual environment
cd \~\myproject\
virtualenv venv
cd venv
The previous command created a new directory called venv, and installed some default packages and modules (called 'dependancies'), required by your new virtual environment.
To activate your virtual environment:
Lesson 4
Screen 12 of 16
cd \~\myproject\venv\Scripts
2. Run the 'activate.bat' script to activate your virtual environment, by typing the following command and pressing return.
1. Change into the Scripts directory, inside your venv directory (as shown), with cmd and the cd command. Press return.
activate.bat
3. The virtual environment is active if your command line begins with (venv), in cmd (as shown).
(venv) ~\myproject\venv\Scripts
To deactivate an active virtual environment: select the cmd window you started the virtual environment from and press the keys ctrl + c.
Repeat the previous steps to reactivate it.
Lesson 4
Screen 13 of 16
Your development environment is ready for use.
You can use the pip package manager to install packages into an active virtual environment. The packages you install inside a virtual environment will not be installed system-wide. This retains the current state of your computer's Python installation.
(venv) pip install flask
To install Flask into your virtual environment:
Lesson 4
Screen 14 of 16
Fill in the missing word. Changes made to one virtual environment do not _____ another (A, B or C)?
A. effect B. control C. install
True or false?
A. cmd B. venv C. pip
A. deletes B. creates C. activates
Which of the following is a package manager for Python (A, B or C)?
A virtual environment uses multiple installations of Python.
Fill in the missing word. The command 'virtualenv venv' _____ a virtual environment (A, B or C)?
Complete the quiz to test your knowledge of virtual environments. Move forward to reveal the answers.
1.
2.
3.
4.
A. effect
false
C. pip
B. creates
You have completed Lesson 4 on creating your development environment. Now you can:
Lesson 4
Screen 15 of 16
Proceed to Lesson 5, where you will use your development environment to create your first local Flask Web application.
Lesson 4
Screen 16 of 16
By mar5us
First Flask App on PythonAnywhere Lesson 4