UNIT A LESSON A2

 

Creating a Virtual Environment

 

Unit A Lesson A2

Screen 1 of 11

Course progress review

This is lesson 2 of 8

 

1) Installing Python

2) Creating a virtual environment

3) Installing Flask

4) Configuring Flask

5) Building your first local Flask app

6) Running your first Flask app

7) Understanding web servers

8) Deploying to PythonAnywhere

Unit A Lesson A2

Screen 2 of 11

Lesson outcomes

This lesson prepares you to:

 

  • Create a new virtual environment for your app by: 
    • installing virtualenv
    • creation of a new virtual environment folder
    • activation of the virtual environment
    • test and confirm activation
  • Understand what you have created and why

Unit A Lesson A2

Screen 3 of 11

A virtual environment is an isolated working copy of Python which allows you to work on a specific project without affecting other projects

Unit A Lesson A2

Screen 4 of 11

What is a virtual environment?

Advantages

of a virtual environment

 

 

1) It enables multiple side-by-side installations of Python, one for each project

2) It doesn't install separate copies of Python

3) It keeps different project environments separated

Unit A Lesson A2

Screen 5 of 11

Creation of a virtual environment in 3 steps

Step 1. Installation

You'll install virtualenv in your project folder

 

Step 2. Creation

You'll create your virtual environment (VE)

 

Step 3. Activation

You'll activate your VE and verify its activation

 

RIGHT! Let's go and do it!  

Unit A Lesson A2

Screen 6 of 11

Creation of a virtual environment - STEP 1

 

Please install virtualenv by :

  1. Opening a command prompt

    • type cmd into windows search to open dialogue box

  2. Type pip install virtualenv into the command line

Unit A Lesson A2

Screen 7 of 11

next we will create the virtual environment

Creation of a virtual environment - STEP 2

 

Please create your virtual environment by:

  1. Opening your previously created project folder

    • use command cd to change the directory

    • e.g. cd c:\IEUser\myproject (if this is your project directory)  

  2. Creation of the virtual environment in your project folder

    • Type virtualenv venv into the cmd prompt

    • This creates a new folder called venv with subfolders

  3. Change ​into the new venv folder

    • ​​Type cd venv

 

Unit A Lesson A2

Screen 8 of 11

next we will activate the virtual environment

Creation of a virtual environment - STEP 3

 

Please activate your virtual environment by:

  1. From the venv folder open the scripts folder

    • type cd scripts taking you c:\IEUser\myproject\venv\scripts

    • e.g. cd c:\IEUser\myproject (if this is your project directory)  

  2. Activate the new virtual environment

    • Type activate.bat

  3. Verify that the virtual environment is active

    • ​​The command line should begin with (venv) c:\ etc

Unit A Lesson A2

Screen 9 of 11

Lesson review

Having completed Unit A Lesson A2 you should now successfully be able to:

 

  • understand the concept of a virtual environment 
  • instal a virtual environment in your project folder
  • activate the virtual environment 
  • verify that activation has taken place 

 

Unit A Lesson A2

Screen 10 of 11

Now it is your turn

Please click on the link below and perform the short quiz before you proceed to Unit B1:

Unit A Lesson A2

Screen 11 of 11

Unit A - Lesson A2

By dwjk

Unit A - Lesson A2

Python Unit A Lesson 2

  • 85