Skip to content

How to Create a Conda Environment

Published on

Updated on

A conda environment is an isolated folder that holds its own Python interpreter and set of packages. Creating one lets each project pin the versions it needs without conflicting with your other projects or your base install — the fix for "it works in one project but breaks another."

Quick answer

To create a conda environment with a specific Python version and switch into it, run:

conda create --name myenv python=3.11
conda activate myenv

Two common variations: build from a shared environment.yml file, or clone an existing environment.

# Create from a YAML spec file
conda env create -f environment.yml
 
# Clone an existing environment
conda create --name newenv --clone oldenv
TaskCommand
Create with Python versionconda create --name myenv python=3.11
Create with packagesconda create --name myenv python=3.11 numpy pandas
Create from YAML fileconda env create -f environment.yml
Clone an environmentconda create --name newenv --clone oldenv
Create in a custom pathconda create --prefix ./envs/myenv python=3.11
Activate itconda activate myenv

--name has the short form -n. So conda create -n myenv python=3.11 is identical to the long form above.

What is a Conda Environment?

A Conda environment is an isolated directory containing a specific collection of packages and their dependencies. Each environment operates independently, allowing you to:

  • Use different Python versions for different projects
  • Install conflicting package versions without issues
  • Share reproducible development setups with teammates
  • Keep your base installation clean and stable

Full Command Reference

The table above covers the most common creation tasks. These are the surrounding commands you will reach for once the environment exists:

TaskCommand
Create empty environmentconda create --name myenv
List all environmentsconda env list
Deactivate current environmentconda deactivate
Update an environment from YAMLconda env update -f environment.yml --prune
Export an environment to YAMLconda env export --from-history > environment.yml
Remove environmentconda env remove --name myenv

Creating a Basic Conda Environment

The simplest way to create a Conda environment uses the conda create command:

conda create --name myenv

This creates an empty environment named myenv. To create and activate it in one workflow:

conda create --name myenv
conda activate myenv

After activation, your terminal prompt changes to show the active environment name.

Creating an Environment with a Specific Python Version

Most projects require a specific Python version. Specify it during creation:

conda create --name myenv python=3.11

You can also specify a version range:

# Python 3.10 or higher
conda create --name myenv python>=3.10
 
# Python 3.9.x (any patch version)
conda create --name myenv python=3.9

Supported Python Versions

Conda can install any released CPython version through the python=X.Y pin. As a rule of thumb, pick a version that is in the current stable range and still receives security fixes — avoid versions that have reached end-of-life unless a legacy project forces it.

Python VersionStatusRecommended For
3.13 / 3.12Current stableNew projects, latest language features
3.11Current stableProduction applications, broad library support
3.10MaintenanceMost libraries compatible
3.9Maintenance (nearing end of life)Legacy project support
3.8 and olderEnd of lifeNo longer receives security fixes

Python's release cycle moves every year, so treat "current stable" as the safer target rather than pinning whatever the single newest number happens to be today. Check the official Python version status (opens in a new tab) if you need the exact end-of-life dates.

Creating an Environment with Packages

Install packages during environment creation to save time:

conda create --name dataenv python=3.11 numpy pandas matplotlib scikit-learn

Specify package versions for reproducibility:

conda create --name dataenv python=3.11 numpy=1.24 pandas=2.0 matplotlib=3.7

Creating an Environment from a YAML File

For complex projects, define environments in a YAML file. This approach enables version control and easy sharing.

Creating the environment.yml File

name: myproject
channels:
  - conda-forge
  - defaults
dependencies:
  - python=3.11
  - numpy=1.24
  - pandas=2.0
  - scikit-learn=1.3
  - matplotlib=3.7
  - jupyter
  - pip
  - pip:
    - pygwalker
    - some-pip-only-package

Creating the Environment from YAML

conda env create -f environment.yml

This command reads the file and creates an environment with the specified name and packages.

Updating an Existing Environment from YAML

conda env update -f environment.yml --prune

The --prune flag removes packages not listed in the YAML file.

Cloning an Existing Environment

Duplicate an environment to experiment without affecting the original:

conda create --name newenv --clone oldenv

This copies all packages and their exact versions. Useful scenarios include:

  • Testing package upgrades safely
  • Creating project-specific variations
  • Backing up a working environment before major changes

Creating Environments in Custom Locations

By default, Conda stores environments in the envs directory. Create an environment elsewhere using --prefix:

conda create --prefix ./envs/myenv python=3.11

Activate it with the full path:

conda activate ./envs/myenv

This approach keeps project dependencies within the project folder.

Best Practices for Conda Environments

1. Use Descriptive Names

Name environments after projects or purposes:

# Good
conda create --name webapp-backend python=3.11
conda create --name data-analysis python=3.10
 
# Avoid
conda create --name env1
conda create --name test

2. Always Specify Python Version

Explicit versions prevent unexpected behavior:

conda create --name myenv python=3.11

3. Export Environments for Sharing

Create reproducible environment files:

# Full export (platform-specific)
conda env export > environment.yml
 
# Cross-platform export
conda env export --from-history > environment.yml

4. Use conda-forge Channel

The conda-forge channel offers more packages and faster updates:

conda create --name myenv -c conda-forge python=3.11 numpy pandas

5. Keep Environments Minimal

Install only necessary packages. Remove unused environments regularly using the conda env remove command.

Troubleshooting Common Issues

Environment Creation Fails

Problem: ResolvePackageNotFound error

Solution: Try using conda-forge channel or check package name spelling:

conda create --name myenv -c conda-forge python=3.11 package-name

Slow Environment Creation

Problem: Solving environment takes too long

Solution: Use mamba, a faster drop-in replacement:

conda install -n base -c conda-forge mamba
mamba create --name myenv python=3.11 numpy pandas

Conda Not Found After Installation

Problem: conda: command not found

Solution: Initialize Conda for your shell:

conda init bash  # or zsh, fish, powershell

Then restart your terminal.

Managing Your Environments

After creating environments, you'll need to manage them effectively:

  • List environments: conda env list shows all environments and their locations
  • Remove environments: See our guide on how to remove Conda environments for detailed instructions
  • Update packages: Use conda update --all within an activated environment

Conda Create vs Conda Env Create

Two commands exist for creating environments:

Featureconda createconda env create
Create empty environmentYesNo
Specify packages inlineYesNo
Create from YAMLNoYes
Clone environmentsYesNo

Use conda create for quick, inline environment creation. Use conda env create when working with YAML files.


FAQ

How do I create a Conda environment with a specific Python version?

Use conda create --name myenv python=3.11 replacing 3.11 with your desired version. Conda downloads and installs the specified Python version in the new isolated environment.

What is the difference between conda create and conda env create?

conda create creates environments with packages specified inline on the command line. conda env create creates environments from YAML specification files. Use conda create for quick setups and conda env create for reproducible, version-controlled environments.

How do I create a Conda environment from a requirements.txt file?

First create the environment, then install from requirements.txt: conda create --name myenv python=3.11 followed by pip install -r requirements.txt after activating the environment. For better compatibility, convert requirements.txt to environment.yml format.

Can I create a Conda environment in a specific directory?

Yes, use the --prefix flag: conda create --prefix ./myenv python=3.11. This creates the environment in the specified path instead of the default Conda envs directory. Activate it using the full path.

Related Guides

📚