Conda environments

Published by Loïc Lejoly on

This article will discuss the benefits of using virtual environments to develop your applications and scripts without being dependent upon libraries already installed on your computer. In addition, this avoids adding new dependencies on your computer.

Why virtual environments ?

Using a virtual environment to develop your projects becomes essential, especially in data science. The reasons of that success resides in the facility to install libraries rapidly without impacting  computer dependencies. Moreover, by giving a list of all packages and their version used, you have the possibility to export this environment from one machine to another, without the need for in-depth knowledge of the package manager.

This is an advantage when you have to collaborate with managers or  people who do not necessarily have an understanding of the resources used by your project. They just want a working environment to run a demo to present to the client.

Using virtual environment is probably one solution to have a working environment in minutes. When the demo is finished, your manager can delete the environment  without affecting his computer.

Why Conda ?

Depending on the software used to create the environment, the features proposed  can be different. In this scope, anaconda is probably one of the post popular software applications to manage your virtual environments, as well a package management system. Unlike some virtual environment software, anaconda is not only focused on Python language. Indeed, you can do anything you want if the package is provided by anaconda. For instance you can install R packages, R-studio, gcc, jupyter, …. You can mostly do anything with anaconda, but keep in mind, sometimes, a more suitable solution exist.

For instance: installing R-studio inside a virtual environment is not super-efficient, so it is better if you install it directly on your computer without using a virtual environment especially if you use R-studio for several projects.

How to install Conda?

The installation process is rather easy and Anaconda is cross-platform, so you can use it on Linux, macOS, and Windows. Two different versions of anaconda are available. On one hand, you have the version with a user interface integrated and with extra tools already installed (details). On the other hand, you can install a light version that only uses the command line (details).

How to create my first environment?

To create a new  Python environment it is easy.

For command line: you need to type the following command inside the anaconda prompt(Windows) or directly inside your favorite terminal (make sure path variables are correctly defined).

Conda create -n MyFirstEnv python=3.7

For User Interface: You need to open anaconda –> Environments –> Create. After that, you can give a name to your environment and select the appropriate version of Python, if you want an environment with Python installed.

Example of Anaconda Window for creating a virtual environment