Comprehensive Guide to Python Virtual Environments using Conda for Data Scientists
Guide to Virtual Environments with Conda via Terminal

This article will be a comprehensive guide for Data Scientists towards using Conda to create, export and use virtual environments for your projects. This tutorial will be dedicated towards Python virtual environments in specific. The following outlines the structure of the article.
Table of Contents
- What are Conda Virtual Environments?
- Why use Virtual Environments?
- Conda Installation
- Create a Virtual Environment - Through Command Line - Through Environment File - Activate Environment - Deactivate Environment
- Environment List - List of Installed Packages in Environment
- Export Virtual Environment
- Cloning a Virtual Environment
- Deleting Virtual Environment(s)
- Concluding Remarks
- Resources
What are Conda Virtual Environments?
In simplest terms, a virtual environment is simply a directory located on your computer to run your scripts in an isolated location. You have the capabilities of creating many different virtual environments, each environment will be isolated from each other. This allows you to run your projects & code with various packages in different versions.
There are various services which provide you to create virtual environments, these services vary from coding language to coding language. For Python in particular, the two most common ways of creating and using virtual environments are through the package managers pip and conda . Although their functionalities may overlap, the overall design for each manager is different. The main reason I use conda for managing my virtual environments is because it is robust and adaptable to package installations through conda and pip, it allows installation of different versions of Python and other programming languages and the software was designed and geared towards Data Scientists.
Why use Virtual Environments?
The use of virtual environments is crucial in Data Science, especially when collaborating on projects, handing off the project for productionalization, managing package dependency conflicts, and making it easier to reproduce results. Python isn’t the best tool for managing packages, each package you install on your computer comes with several other packages which the current package relies on. All of those packages are then installed at various versions to make sure the latest installed package is functioning. This becomes problematic without specifying the inspecting the versions associated to the packages you’re installing.
Suppose you’re working on project Y and you’re using version 2.0.1 of pandas , however when working on project X, you were using version 2.0.0 of pandas . Imagine that the differences between these versions comes with the deprecation of various functions on pandas which project X was using. This essentially means that the scripts you wrote for project X which called the deprecated functions will no longer work as the version of your library has updated. This issue might not arise when you’re just beginning your journey into data science and don’t have a lot of projects under your belt, but at some point you will run into this or a very similar problem.
It is best practice to have an independent virtual environment per project you’re working on. This is due to two main reasons; firstly, the dependencies and versions for the projects may differ and you continue to work on more and more projects. Secondly, the production environment would require those dependencies and their associated versions. Older / newer versions might have deprecated or new functions added to the library. When handing off your models to a data / machine learning engineer to place into production, you would provide them the model, a script associated with using the model to generate predictions and a requirements / environment file which holds the packages and versions of those packages necessary to load & run the model.
Conda Installation
Conda has extensive documentation on their installation. Following the guide below will indicate the necessary steps and instructions associated with installing anaconda / miniconda in a Windows / Mac / Linux operating system.
Create a Virtual Environment
Through Command Line
At any path in your terminal / command line after you have conda installed, you can run the following command :
conda create -n <env_name>The -n stands for name and you replace the <env_name> with the name of the environment you want to create. For the purposes of this tutorial, I will create an environment called conda_tutorial through the following command. A good tip is to keep the environment name very similar or related to the project you’re going to be using this environment for.
conda create -n conda_tutorialYou’re also able to specify the version of Python you want to be created with the environment through the following command :
conda create -n conda_tutorial python=3.9Based on the Conda documentation, if no Python version is specified when creating the environment, it will use Python 3.9 by default [3].
Through Yaml File
The following is the structure associated with a conda environment file, typically named environment.yml .










