conda

Miniconda installation and usage guide for Windows, macOS, and Linux. Includes environment management and package installation commands

This document provides instructions for installing Miniconda and basic usage examples.

Installation

Windows

  1. Download the Miniconda installer for Windows from the official website.
  2. Run the installer and follow the prompts.
  3. Optionally, add Miniconda to your PATH during installation.

macOS/Linux

  1. Download the appropriate installer from the official website.

  2. Open a terminal and run:

    bash Miniconda3-latest-Linux-x86_64.sh
    
  3. Follow the installation prompts.

Basic Usage

Create a New Environment

conda create -n myenv python=3.9

Activate an Environment

conda activate myenv

Deactivate an Environment

conda deactivate

List Environments

conda env list

Install Packages

conda install numpy pandas

Update Conda

conda update conda

Installing Ansible Kubernetes Collection

To install the kubernetes.core collection for Ansible in a Conda environment named ansible, run:

conda run -n ansible ansible-galaxy collection install kubernetes.core

Explanation:

  • conda run -n ansible runs the command inside the ansible Conda environment.
  • ansible-galaxy collection install kubernetes.core installs the Kubernetes collection for Ansible.

Alternative: Install from requirements.yml

If you have a requirements.yml file listing required collections, install all at once:

conda run -n ansible ansible-galaxy collection install -r requirements.yml
### Sample requirements.yml
collections:
   - name: kubernetes.core
   - name: community.kubernetes
   - name: cloud.common
   - name: community.postgresql
   - name: bitwarden.secrets

This is useful for managing multiple collections and keeping dependencies organized.

Creating or Updating a Conda Environment with environment.yml

You can manage your Conda environment using an environment.yml file. This file lists all dependencies and configuration for your environment.

To create a new environment from environment.yml:

conda env create -f environment.yml

To update an existing environment:

conda env update -f environment.yml

Example environment.yml for an Ansible environment:

name: ansible
channels:
  - conda-forge
dependencies:
  - python=3.12
  - pip
  - pip:
      - ansible
      - ansible-lint
      - psycopg2
      - bitwarden-sdk

Automate Create/Update for the ‘ansible’ Environment

The following shell script checks if the ansible environment exists and updates it if found, or creates it if not:

if conda env list | grep -q '^ansible[[:space:]]'; then
   echo "Updating existing Ansible environment..."
   conda env update -f environment.yml
else
   echo "Creating new Ansible environment..."
   conda env create -f environment.yml
fi

Explanation:

  • Lists all Conda environments and checks for one named ansible.
  • Updates the environment if it exists, otherwise creates it.

References