Working with Virtual Environments in Anaconda.

Fabian Christopher
featurepreneur
Published in
3 min readJun 2, 2021

--

Introduction

Hey there! If you’re reading this, there’s a high chance you've already come across the term environments. An environment can simply be defined as a virtual lab where you can deploy as many libraries and packages as you want and experiment with them without the fear of affecting the functionally of other environments or your system as a whole.

The ability to have a custom environment for your project is one of the most powerful features of Anaconda. In this article, I will guide you through how you can easily set up and work with environments in Anaconda.

Requirements

  • A machine with Anaconda installed.
  • That’s all you need to get started xD

Head over to Anaconda docs if you’re yet to install and configure Anaconda in your machine

https://docs.anaconda.com/anaconda/install/

Overview

  • Creating a conda environment
  • Installing packages
  • Toggling your environment on/off
  • Installing additional packages
  • Updating packages.

With that said, Let’s Get Started

Creating a Conda Environment

  • To create a simple Conda environment, the syntax is as follows:
conda create -n <Environment Name>
  • For example:
conda create -n Demo

Installing Packages

  • To install the specific version of a package you want while creating the environment, the syntax is as given below. You may specify parameters such as “greater than”, “lesser than” or just specify your desired version.
conda create -n <Environment Name> <Package Name> == <Version>
conda create -n <Environment Name> <Package Name> <= <Version>
conda create -n <Environment Name> <Package Name> >= <Version>
  • For example:
conda create -n Demo python == 3.7
conda create -n Demo python <= 3.7
conda create -n Demo python >= 3.7
  • The syntax is given below to specify multiple packages along with their version requirements in the same command.
conda create -n Demo python == 3.7 tensorflow == 2.0
  • If you wanna let the install set the appropriate versions, you can just specify the package names as follows:
conda create -n Demo python tensorflow

Toggling your Environment On/Off

  • Now, to View your Available environments, use the following command:
conda env list
  • Now, to activate the environment you want to work in, the syntax is as follows:
conda activate <Environment Name>
  • For example:
conda activate Demo
  • To exit the current environment or to deactivate it, the syntax is as follows:
conda deactivate <Environment Name>
  • For example:
conda deactivate Demo

Install Additional packages

  • To install any additional packages in the environment, the syntax is as follows:
pip install <package name>
  • For example:
pip install tensorflow
  • If you want to use python 3 specifically, use pip3 as follows:
pip3 install <package name>
  • For example:
pip3  install tensorflow

Updating packages

  • If you want to upgrade an existing package to the latest version, the command is as follows:
pip install --upgrade <package name>
  • For example:
pip install --upgrade tensorflow
  • If you want to use python 3 specifically for upgrading, use pip3 as follows:
pip3 install --upgrade <package name>
  • For example:
pip3 install --upgrade tensorflow

Conclusion

Working with anaconda environments can be fun and powerful if you master these commands. Hope you have fun working with Anaconda! Do check out my other articles where I cover topics such as deep learning and other trending technologies.

Thanks for stopping by! Happy Learning!

You can check out my Linkedin at https://www.linkedin.com/in/fabchris10/

--

--