Python Virtual Environments Tutorial for Beginners

Natetthompson
3 min readMar 28, 2021

Introduction

A typical Python based data science or machine learning project can require a plethora of libraries. Keeping track of all of these libraries and version is key to maintaining the portability and collaborative aspects of your project.

Even a bare bones Python analysis project requires libraries such as numpy and pandas for data transformation or Tensorflow and scikit-learn for machine learning. Each of those libraries may also require their own dependencies for specific versions.

As you can see successfully managing dependencies can make developing your project easier. Luckily Python includes options for handling such needs. It is highly encouraged that you get into the habit of creating a virtual environment for each of your projects in order to avoid dependency collisions.

Virtual Environments

The venv utility is an easy to use module that provides an isolated layer for your Python application.

You can install the venv through pip. Just be sure that the version you are installing matches the Python version installed on your machine. For example for Python 3.6.x you would run the command.

$ sudo apt install python3.6-venv

--

--

Natetthompson
Natetthompson

No responses yet