Setting up Development environment with virtualenv

Ajay TekamAjay Tekam
1 min read

Virtualenv is a Python module which helps to create isolated Python environments for our scripting experiments, which creates a folder with all necessary executable files and modules for a basic Python project.

Virtual environments help to separate dependencies required for different projects, by working inside a virtual environment it also helps to keep our global site-packages directory clean.

But before that we have to install pip3 package. Pip is a package management system used to install and manage software packages written in Python. pip3 is a python3 package manager.

Pip3 Installation

apt install python3-pip

Now install virtualenv

pip3 install virtualenv

Usage

  • Create folder project where you can write your code
mkdir mycode
cd mycode
  • Now create virtualenv environment files inside project folder
virtualenv name-of-virtual-environment
virtualenv venv
  • To create a virtual environment with a particular python version, use below command
virtualenv -p python2.7 venv
  • Activate the virtual environment by
source venv/bin/activate  

// or 

. venv/bin/activate

Now you can install any dependencies and use it, which is isolated to this configuration only. To install new packages you can use pip or pip3 etc on this environment. For example

pip3 install package_name
  • Exit from the virtualenvironment, type
deacticate
0
Subscribe to my newsletter

Read articles from Ajay Tekam directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ajay Tekam
Ajay Tekam

I am working as a Cloud Engineer with experience in DevOps, automation, CICD, build pipelines, jenkins pipelines, version control, shell scripting, python automation, golang automation, cloud services (AWS, OCI, Azure), containers and microservices, terraform, ansible.