0% found this document useful (0 votes)
13 views3 pages

Conda Commands

This document is a comprehensive cheat sheet for using Conda, a package and environment management tool for Python. It includes commonly used commands for installing Conda, managing environments, handling packages, exporting/importing environments, and cleaning up. The document also provides an example workflow demonstrating the creation, activation, and removal of a Conda environment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

Conda Commands

This document is a comprehensive cheat sheet for using Conda, a package and environment management tool for Python. It includes commonly used commands for installing Conda, managing environments, handling packages, exporting/importing environments, and cleaning up. The document also provides an example workflow demonstrating the creation, activation, and removal of a Conda environment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Conda is a powerful package management and environment management tool for Python

and other languages. Here’s a comprehensive list of commonly used **Conda


commands** along with examples:

---

### 1. **Install Conda**


- Install Miniconda or Anaconda from their respective websites:
- Miniconda:
[https://docs.conda.io/en/latest/miniconda.html](https://docs.conda.io/en/latest/
miniconda.html)
- Anaconda:
[https://www.anaconda.com/products/distribution](https://www.anaconda.com/
products/distribution)

---

### 2. **Basic Information Commands**


| Command | Description |
Example |
|-------------------------------------|-------------------------------------|------
---------------------------------------|
| `conda --version` | Check Conda version | `$
conda --version` |
| `conda info` | Display general Conda information | `$
conda info` |
| `conda list` | List all installed packages | `$
conda list` |

---

### 3. **Working with Environments**


| Command | Description
| Example |
|-------------------------------------|--------------------------------------------
---------|----------------------------------------------|
| `conda create --name ENV_NAME` | Create a new environment
| `$ conda create --name my_env` |
| `conda create -n ENV_NAME PKG_NAME` | Create environment with specific package(s)
| `$ conda create -n my_env numpy pandas` |
| `conda env list` | List all environments
| `$ conda env list` |
| `conda activate ENV_NAME` | Activate an environment
| `$ conda activate my_env` |
| `conda deactivate` | Deactivate the current environment
| `$ conda deactivate` |
| `conda remove --name ENV_NAME --all`| Remove an environment
| `$ conda remove --name my_env --all` |

---

### 4. **Managing Packages**


| Command | Description
| Example |
|---------------------------------------------|------------------------------------
--------|--------------------------------------------|
| `conda install PKG_NAME` | Install a package
| `$ conda install numpy` |
| `conda install PKG_NAME=VERSION` | Install a specific package version
| `$ conda install numpy=1.21.0` |
| `conda install -c CHANNEL_NAME PKG_NAME` | Install a package from a specific
channel | `$ conda install -c conda-forge matplotlib`|
| `conda update PKG_NAME` | Update a package
| `$ conda update scipy` |
| `conda update conda` | Update Conda
| `$ conda update conda` |
| `conda uninstall PKG_NAME` | Uninstall a package
| `$ conda uninstall pandas` |

---

### 5. **Cloning an Environment**


| Command | Description |
Example |
|----------------------------------------|-----------------------------------|-----
--------------------------------------|
| `conda create --name NEW_ENV --clone OLD_ENV` | Clone an existing environment
| `$ conda create --name new_env --clone old_env` |

---

### 6. **Exporting and Importing Environments**


| Command | Description
| Example |
|----------------------------------------|-----------------------------------------
---|-------------------------------------------|
| `conda env export > env.yml` | Export current environment to a YAML
file | `$ conda env export > my_env.yml` |
| `conda env create -f env.yml` | Create an environment from a YAML file
| `$ conda env create -f my_env.yml` |

---

### 7. **Searching for Packages**


| Command | Description | Example
|
|--------------------------------|----------------------------------|--------------
----------------------------|
| `conda search PKG_NAME` | Search for a package | `$ conda
search matplotlib` |

---

### 8. **Cleaning Up**


| Command | Description |
Example |
|-----------------------------|--------------------------------------------|-------
------------------------------------|
| `conda clean --all` | Remove unused packages and cache files | `$
conda clean --all` |

---

### 9. **Working with Channels**


| Command | Description
| Example |
|-------------------------------------------------|--------------------------------
-----------------|-------------------------------------------|
| `conda config --show channels` | Show the list of configured
channels | `$ conda config --show channels` |
| `conda config --add channels CHANNEL_NAME` | Add a new channel
| `$ conda config --add channels conda-forge`|
| `conda config --remove channels CHANNEL_NAME` | Remove a channel
| `$ conda config --remove channels conda-forge`|

---

### 10. **Environment Backup**


- **Create a backup of all environments:**
```bash
$ conda list --explicit > spec-file.txt
```
- **Restore from the backup:**
```bash
$ conda create --name ENV_NAME --file spec-file.txt
```

---

### Example Workflow


1. Create a new environment and install packages:
```bash
conda create --name data_env numpy pandas matplotlib
```
2. Activate the environment:
```bash
conda activate data_env
```
3. Install additional packages:
```bash
conda install seaborn
```
4. Export the environment:
```bash
conda env export > data_env.yml
```
5. Deactivate and remove the environment:
```bash
conda deactivate
conda remove --name data_env --all
```

This cheat sheet provides all key commands to work efficiently with Conda.

You might also like