Skip to content

Virtual Environments

Installing Virtualenv

Assuming python 3 it is already installed as well as pip we can start in this way:

pip install virtualenv

virtual_eniroments_001

Creating the Virtual Environment

Now we can select the directory where we are going to save the virtual environment, in this example we will use the directory "/Users/victoraguirre/Documents/026.workspace_Python", and we can provide a name for it ( virtual environment), in this case i will choose virtualEnv000

virtualenv -p python3 /Users/victoraguirre/Documents/026.workspace_Python/virtualEnv000

virtual_enviroment_002

Activate environments

now a Folder with the name of the environment it is going to be created, the first step to activate the environment will be to navigate to that folder

virtual_environments

and later call the activate file that is inside the bin directory

1
2
3
4
5
6
7
// on Mac
cd /Users/victoraguirre/Documents/026.workspace_Python/virtualenv
source bin/activate

// On windows
call /Users/victoraguirre/Documents/026.workspace_Python/virtualenv
source bin/activate.bat

virtual_environments_004

As part of this exercise I will install Flask inside this virtual environment

Install packages and create a file

now lets install flask

pip install flask

here the basic code for a page in flash

virtual_environments_005

now running

python app.py

we have the server running ans the website up ( default IP http://127.0.0.1:5000)

virtual_environments_006

virtual_environments_007

Deactivate environment

Now, to stop the environment we just need to type deactivate

virtual_environments_008