Python

Create and switch conda environments

Install Miniconda, then give each project its own conda environment with its own Python version and packages.

Fill these in once
  1. Install Miniconda
    Terminal
    brew install --cask miniconda

    Miniconda is the small version of Anaconda: just conda and Python, no extra apps.

  2. Let your terminal use conda
    Terminal
    conda init "$(basename "$SHELL")"

    Close the terminal and open a new one afterwards. Your prompt now starts with (base).

  3. Create an environment with its own Python
    Terminal
    conda create -n myenv python=3.12

    Type y when it asks to go ahead. Each environment has its own Python and packages.

  4. Switch to it
    Terminal
    conda activate myenv

    Your prompt now starts with ({{name}}).

  5. Install packages into it
    Terminal
    conda install numpy

    pip install also works inside a conda environment. Use conda first, pip for anything conda doesn't have.

  6. See all your environments
    Terminal
    conda env list

    The one marked with * is the one you're in.

  7. Switch back out
    Terminal
    conda deactivate
  8. Save the environment to a file to share it
    Terminal
    conda env export --from-history > environment.yml

    --from-history keeps only the packages you asked for, so the file works on other computers too.

  9. Recreate it from that file on another computer
    Terminal
    conda env create -f environment.yml

Check it worked

  1. Check which environment you're in
    Terminal
    conda info --envs
  2. Check its Python version
    Terminal
    python --version
Undo it
  1. Leave the environment
    Terminal
    conda deactivate
  2. Delete the environment
    Terminal
    conda env remove -n myenv

    Your project files are not touched. Only the environment's Python and packages go.

  1. Download the Miniconda installer
    Terminal · Ubuntu / Debian
    curl -fsSLo miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

    On an ARM computer, swap x86_64 for aarch64.

  2. Run it
    Terminal · Ubuntu / Debian
    bash miniconda.sh -b -p ~/miniconda3

    -b installs without questions into ~/miniconda3 in your home folder.

  3. Let your terminal use conda
    Terminal · Ubuntu / Debian
    ~/miniconda3/bin/conda init "$(basename "$SHELL")"

    Close the terminal and open a new one afterwards. Your prompt now starts with (base).

  4. Create an environment with its own Python
    Terminal · Ubuntu / Debian
    conda create -n myenv python=3.12

    Type y when it asks to go ahead. Each environment has its own Python and packages.

  5. Switch to it
    Terminal · Ubuntu / Debian
    conda activate myenv

    Your prompt now starts with ({{name}}).

  6. Install packages into it
    Terminal · Ubuntu / Debian
    conda install numpy

    pip install also works inside a conda environment. Use conda first, pip for anything conda doesn't have.

  7. See all your environments
    Terminal · Ubuntu / Debian
    conda env list

    The one marked with * is the one you're in.

  8. Switch back out
    Terminal · Ubuntu / Debian
    conda deactivate
  9. Save the environment to a file to share it
    Terminal · Ubuntu / Debian
    conda env export --from-history > environment.yml

    --from-history keeps only the packages you asked for, so the file works on other computers too.

  10. Recreate it from that file on another computer
    Terminal · Ubuntu / Debian
    conda env create -f environment.yml

Check it worked

  1. Check which environment you're in
    Terminal · Ubuntu / Debian
    conda info --envs
  2. Check its Python version
    Terminal · Ubuntu / Debian
    python --version
Undo it
  1. Leave the environment
    Terminal · Ubuntu / Debian
    conda deactivate
  2. Delete the environment
    Terminal · Ubuntu / Debian
    conda env remove -n myenv

    Your project files are not touched. Only the environment's Python and packages go.

  1. Install Miniconda
    PowerShell
    winget install -e --id Anaconda.Miniconda3

    Miniconda is the small version of Anaconda: just conda and Python, no extra apps. You can also use the Anaconda Prompt app it adds to the Start menu.

  2. Let your terminal use conda
    PowerShell
    conda init powershell

    If conda isn't found, run this from the Anaconda Prompt app. Then close PowerShell and open a new one; your prompt starts with (base).

  3. Create an environment with its own Python
    PowerShell
    conda create -n myenv python=3.12

    Type y when it asks to go ahead. Each environment has its own Python and packages.

  4. Switch to it
    PowerShell
    conda activate myenv

    Your prompt now starts with ({{name}}).

  5. Install packages into it
    PowerShell
    conda install numpy

    pip install also works inside a conda environment. Use conda first, pip for anything conda doesn't have.

  6. See all your environments
    PowerShell
    conda env list

    The one marked with * is the one you're in.

  7. Switch back out
    PowerShell
    conda deactivate
  8. Save the environment to a file to share it
    PowerShell
    conda env export --from-history | Out-File -Encoding utf8 environment.yml

    --from-history keeps only the packages you asked for, so the file works on other computers too.

  9. Recreate it from that file on another computer
    PowerShell
    conda env create -f environment.yml

Check it worked

  1. Check which environment you're in
    PowerShell
    conda info --envs
  2. Check its Python version
    PowerShell
    python --version
Undo it
  1. Leave the environment
    PowerShell
    conda deactivate
  2. Delete the environment
    PowerShell
    conda env remove -n myenv

    Your project files are not touched. Only the environment's Python and packages go.