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 myenvTwo 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| Task | Command |
|---|---|
| Create with Python version | conda create --name myenv python=3.11 |
| Create with packages | conda create --name myenv python=3.11 numpy pandas |
| Create from YAML file | conda env create -f environment.yml |
| Clone an environment | conda create --name newenv --clone oldenv |
| Create in a custom path | conda create --prefix ./envs/myenv python=3.11 |
| Activate it | conda activate myenv |
--namehas the short form-n. Soconda create -n myenv python=3.11is 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:
| Task | Command |
|---|---|
| Create empty environment | conda create --name myenv |
| List all environments | conda env list |
| Deactivate current environment | conda deactivate |
| Update an environment from YAML | conda env update -f environment.yml --prune |
| Export an environment to YAML | conda env export --from-history > environment.yml |
| Remove environment | conda 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 myenvThis creates an empty environment named myenv. To create and activate it in one workflow:
conda create --name myenv
conda activate myenvAfter 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.11You 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.9Supported 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 Version | Status | Recommended For |
|---|---|---|
| 3.13 / 3.12 | Current stable | New projects, latest language features |
| 3.11 | Current stable | Production applications, broad library support |
| 3.10 | Maintenance | Most libraries compatible |
| 3.9 | Maintenance (nearing end of life) | Legacy project support |
| 3.8 and older | End of life | No 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-learnSpecify package versions for reproducibility:
conda create --name dataenv python=3.11 numpy=1.24 pandas=2.0 matplotlib=3.7Creating 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-packageCreating the Environment from YAML
conda env create -f environment.ymlThis 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 --pruneThe --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 oldenvThis 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.11Activate it with the full path:
conda activate ./envs/myenvThis 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 test2. Always Specify Python Version
Explicit versions prevent unexpected behavior:
conda create --name myenv python=3.113. 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.yml4. 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 pandas5. 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-nameSlow 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 pandasConda Not Found After Installation
Problem: conda: command not found
Solution: Initialize Conda for your shell:
conda init bash # or zsh, fish, powershellThen restart your terminal.
Managing Your Environments
After creating environments, you'll need to manage them effectively:
- List environments:
conda env listshows all environments and their locations - Remove environments: See our guide on how to remove Conda environments for detailed instructions
- Update packages: Use
conda update --allwithin an activated environment
Conda Create vs Conda Env Create
Two commands exist for creating environments:
| Feature | conda create | conda env create |
|---|---|---|
| Create empty environment | Yes | No |
| Specify packages inline | Yes | No |
| Create from YAML | No | Yes |
| Clone environments | Yes | No |
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
- How to Remove a Conda Environment - Delete environments you no longer need
- How to Check Your Python Version - Confirm which Python an environment is running
- How to Run Python Scripts - Run code inside your new environment
- Convert Jupyter Notebooks to PDF - Export notebooks built in your conda environment
- Managing conda environments (official docs) (opens in a new tab) - Complete environment management reference