Managing Packages Intermediate

Learn how to install, update, search, and remove packages using conda. Understand the conda-forge channel, when to use conda vs pip, and how to resolve dependency conflicts.

Installing Packages

# Install a single package
conda install numpy

# Install a specific version
conda install numpy=1.25.0

# Install multiple packages
conda install numpy pandas matplotlib scikit-learn

# Install from a specific channel
conda install -c conda-forge plotly

# Install without confirmation prompt
conda install numpy -y

# Install in a specific environment (without activating)
conda install -n myproject numpy

conda-forge Channel

conda-forge is a community-maintained channel with thousands of packages not available in the default Anaconda channel:

# Install from conda-forge
conda install -c conda-forge transformers

# Add conda-forge as a default channel
conda config --add channels conda-forge

# Set channel priority (strict recommended)
conda config --set channel_priority strict

# List configured channels
conda config --show channels

# Remove a channel
conda config --remove channels conda-forge
Recommendation: Add conda-forge as a default channel. It has more packages and often more up-to-date versions than the defaults channel. Use conda config --set channel_priority strict to avoid mixing packages from different channels, which can cause conflicts.

Searching Packages

# Search for a package
conda search numpy

# Search in a specific channel
conda search -c conda-forge transformers

# Search with version constraints
conda search "numpy>=1.24"

# Check if a package is installed
conda list numpy

Updating Packages

# Update a specific package
conda update numpy

# Update all packages in the environment
conda update --all

# Update conda itself
conda update conda

# Update Anaconda meta-package
conda update anaconda

Removing Packages

# Remove a package
conda remove numpy

# Remove multiple packages
conda remove numpy pandas matplotlib

# Remove from a specific environment
conda remove -n myproject numpy

Conda vs pip

Featurecondapip
Package sourceAnaconda/conda-forge repositoriesPyPI (Python Package Index)
Language supportPython, R, C, C++, FortranPython only
Dependency resolutionSAT solver (robust)Backtracking resolver (improved)
Virtual environmentsBuilt-in (conda create)Separate tool (venv/virtualenv)
Binary packagesPre-compiled for your platformWheels or source compilation
Non-Python depsHandles CUDA, MKL, OpenSSL, etc.Cannot manage non-Python deps
Package count~8,000 (defaults) + conda-forge~450,000+ on PyPI

When to Use Each

  • Use conda for: scientific packages (numpy, scipy, tensorflow, pytorch), anything with C/C++ dependencies, creating environments
  • Use pip for: packages only available on PyPI, Python-only packages, the latest version of a package not yet on conda
  • Rule of thumb: Try conda first. If the package is not available, use pip
# Using pip within a conda environment
conda activate myproject

# Install with pip (after conda packages are installed)
pip install some-pypi-only-package

# List pip-installed packages
pip list

# Include pip packages in environment.yml
conda env export > environment.yml
# pip packages appear under a "pip:" section
💡
Important: When mixing conda and pip in the same environment, install all conda packages first, then use pip for the remainder. Running conda install after pip install can sometimes overwrite pip-installed packages.

Resolving Conflicts

# If conda reports conflicts, try:

# 1. Create a fresh environment
conda create -n fresh-env python=3.11

# 2. Use strict channel priority
conda config --set channel_priority strict

# 3. Install all packages at once (better resolution)
conda install numpy pandas scikit-learn tensorflow

# 4. Check for conflicts
conda install numpy --dry-run

# 5. Use mamba for faster resolution
conda install -c conda-forge mamba
mamba install tensorflow  # Much faster than conda

requirements.txt vs environment.yml

Featurerequirements.txtenvironment.yml
FormatSimple text (pip format)YAML (conda format)
Package managerpip onlyconda + pip
Python versionNot specifiedIncluded
ChannelsN/ASpecified (defaults, conda-forge)
Environment nameN/AIncluded
Create commandpip install -r requirements.txtconda env create -f environment.yml
Best forpip/venv projectsconda/Anaconda projects