Episode #20 | Virtualenv

Thursday, 17 Jan 2019 Kudzai Nyandoro 3:41 Minutes


There are several ways to manage Python versions and Python environments and some of these include Pipenv, Anaconda and Virtualenv. This blog will focus on the Virtualenv. According to its online documentation Virtualenv is used to create isolated Python environments. Using a virtual environment helps to keep Python projects isolated and the developer does not have to worry about accidentally changing versions of her libraries, thereby unwittingly breaking her application. Below are some quick steps on how to install and create virtual environments with Virtualenv. You'll need to have Python 3 installed for Virtualenv to work.


Install Virtualenv On MacOS

$ pip install --user virtualenv

Install Virtualenv On Windows

$ pip install virtual env

Create a Virtual Environment

$ mkdir my_app

Change into your new project directory

$ cd my_app

In the code below we create a virtual environment 'my_app'. You can give it any name of your choice.

$ python3 -m venv my_app

Activate your environment, Note: For Windows, leave out the word, source

$ source my_app/bin/activate

Dectivate your environment

$ deactivate