Creating an environment in anaconda through a yml file

Photo by 🇸🇮 Janko Ferlič on Unsplash

Conda environments are independent containers, because of which the package and their version inside will not impact the packages that are outside the environment. creating a virtual environment helps you to play around the packages and dependencies by keeping it isolated from the rest of your code.

We can use yml to create an environment manually or export from the existing environment.

The instructions given in the post are for Windows and written presuming that anaconda has been already installed

Step 1: Building an environment manually

If you want to be more organized and efficient by separating environments for different projects that might require specific libraries, anaconda allows you to easily create environments manually through yml files.

The yml file contains information for the environment you wish to create in the below parts:

Fig 1.
  • Name of environment
  • Dependencies, such as the libraries you wish to pre-install when creating the environment.
  • channels(Optional), refer to channels to download the packages. Packages on conda-forge may be more up-to-date than those on the defaults channel.
Fig 2.

If you want to include some pip package, you can do that too.

As shown in Fig 2. you can add the packages that need to be installed using pip, whereas other packages will be installed using conda.

As shown in fig 2. if any specific version of the library is needed, you have to mention it, else the latest version available will be downloaded.

Step 2: Installing the libraries

After creating a yml file, run the below command. Make sure you have been outside any conda environments.

conda env create -f <path_to_yaml_file>

This will create an environment and install all the dependencies mentioned.

Step 3: Activating the environment

To check whether the environment is created, run the below command.

conda env list

This will list all the environment created.

conda activate <env_name>

This command will activate the environment as shown below.

Step 4: Exporting the Environment file

First, let's activate the environment you want to export

conda env export > environment.yml

This will handles both the conda and pip packages in the environment. This yml can be shared with others to create the same environment as yours

Step 5 (Optional): Including the environment in the Jupyter notebook

By including Ipykernel library in the dependencies and then adding kernel to jupyter notebook, we can use the environment in the jupyter notebook.

For creating virtual environments in anaconda and using it inside jupyter, see here

That’s it for the article. Thanks for reading this, I hope it’ll be useful.

Thank you and stay safe!




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Started From the Bottom Now We’re Here: Problem Solving with Algorithms

They standard arrive allow seat.

How To Create a WordPress Shortcode for flickr Albums

How to Add More Power to Your Flutter App Development

wxWidgets 101: A Minimal Hello World Example for Mac

How To Ace Your Coding Assessments

Organize your starred repositories on GitHub

ElasticSearch integration with Logstash and Kibana to monitor Apache2 logs

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


More from Medium

Introduction to CI pipelines on Github

Two people looking at code on a Silver Macbook Pro

Things that you can do for a running Docker container

Implement Redshift Datashare for Cross AWS Account

Virtualizing your data with IBM Watson Query