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.

 

Print Article

Related Articles (10)

Install Miniconda as user without administrator permissions in Windows.
Install Miniconda as user without administrator permissions on a Mac.
Activate a Conda Environment in the command line interface in Windows.
Create a Conda Environment in the command line interface in Windows.
Open Windows Anaconda Prompt and MacOS Terminal Command Line Interface in a Virtual Conda Environment
A central guide for researchers to build stable and high-performance coding environments using the Conda ecosystem. It brings together best practices—such as choosing the right distribution and using "blueprints" to share work—to help you avoid technical conflicts and ensure your research can be perfectly recreated by others. By following these strategies, you can protect your productivity and make your software projects both portable and reliable.
Think of Conda as a way to create separate, private "workspaces" on your computer for different projects so their software settings don't get mixed up or cause errors. While other tools only handle one coding language, Conda is a "heavy hitter" that can manage almost any software component, making it the top choice for complex fields like Data Science and AI. By using these isolated spaces, you keep your computer stable and make it easy to share your exact setup with others.
Index of Miniconda How-To Articles for Virtual Conda Environments