C.W.K.
Stream
Lesson 03 of 05 · published

Daily conda Commands

~13 min · conda, commands, envs, workflow

Level 0Newbie
0 XP0/55 lessons0/16 achievements
0/80 XP to next level80 XP to go0% complete

conda's CLI separates environment management from package management. Both are centered on the active environment.

Environments. conda create --name myenv python=3.12 creates a new env with Python 3.12. conda activate myenv switches your shell to it (prompt prefixes with (myenv)). conda deactivate exits. conda env list shows all envs. conda remove --name myenv --all deletes one entirely.

Packages. conda install <pkg> installs into the active env. conda install -c conda-forge <pkg> uses a specific channel for this install. conda update --all upgrades every package in the env. conda list shows installed packages. conda remove <pkg> uninstalls.

Reproducibility. conda env export > environment.yml exports the env to YAML. conda env create -f environment.yml recreates it on another machine. conda env update -f environment.yml applies new changes to an existing env.

Code

Environment lifecycle·bash
# Create
conda create --name dl python=3.12

# Activate
conda activate dl
# prompt becomes (dl)

# Use
conda install pytorch torchvision -c pytorch -c conda-forge
conda install jupyterlab pandas matplotlib

# What's installed
conda list

# Leave
conda deactivate

# List all envs
conda env list
#   base                  /Users/you/miniconda3
# * dl                    /Users/you/miniconda3/envs/dl
#   web                   /Users/you/miniconda3/envs/web

# Delete
conda remove --name dl --all
Reproducible env files·bash
# Export current env
conda env export > environment.yml

# Or export only what you explicitly installed (cleaner for sharing)
conda env export --from-history > environment.yml

# Recreate on another machine
conda env create -f environment.yml

# Update an existing env from a changed environment.yml
conda env update -f environment.yml --prune
When to use --from-history·yaml
# Without --from-history (full export — every transitive dep)
name: dl
channels:
  - conda-forge
  - pytorch
dependencies:
  - python=3.12.4=h99cad12_0    # exact build hash
  - pytorch=2.4.0=py3.12_0
  - numpy=1.26.4=py312h7f4f0e0_0
  # ... 200+ more lines, all with build hashes

# With --from-history (just what YOU installed)
name: dl
channels:
  - conda-forge
  - pytorch
dependencies:
  - python=3.12
  - pytorch
  - jupyterlab
  - pandas
  - matplotlib
# Cleaner for sharing across platforms; conda re-resolves on the target machine.

External links

Exercise

Create a fresh env: 'conda create --name scratch python=3.12 && conda activate scratch && conda install -c conda-forge numpy pandas jupyterlab'. Then 'conda env export --from-history > /tmp/env.yml' and read it. The --from-history version is what you'd commit to a repo as 'environment.yml'.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.