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
| Feature | conda | pip |
|---|---|---|
| Package source | Anaconda/conda-forge repositories | PyPI (Python Package Index) |
| Language support | Python, R, C, C++, Fortran | Python only |
| Dependency resolution | SAT solver (robust) | Backtracking resolver (improved) |
| Virtual environments | Built-in (conda create) | Separate tool (venv/virtualenv) |
| Binary packages | Pre-compiled for your platform | Wheels or source compilation |
| Non-Python deps | Handles 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
| Feature | requirements.txt | environment.yml |
|---|---|---|
| Format | Simple text (pip format) | YAML (conda format) |
| Package manager | pip only | conda + pip |
| Python version | Not specified | Included |
| Channels | N/A | Specified (defaults, conda-forge) |
| Environment name | N/A | Included |
| Create command | pip install -r requirements.txt | conda env create -f environment.yml |
| Best for | pip/venv projects | conda/Anaconda projects |
Lilly Tech Systems