How-To: Using Anaconda - Create a Virtual Conda Environment From a YML File via Command Line Interface

Question

How do I create a virtual conda environment using a .yml file from the Command Line?

 

Answer

1. Example environment.yml file that can be used to create or restore a conda environment.  Three sections are shown: name, channels, and dependencies.

 # environment.yml
name: myenv
channels:
  - conda-forge
dependencies:
  - python
  - numpy

 

Note:  To open an Anaconda Prompt in Windows or the Terminal in MacOS, see "How-To: Using Anaconda -  Launch a Virtual Conda Environment via Command Line Interface

2. Create a new conda environment using environment.yml file.

a. Launch base conda environment via Anaconda Prompt or Terminal command line.

b. In base conda environment, enter "conda env create --file environment.yml". 
 

Command prompt with "conda env create --file environment.yml" and creation results.