Introduction
Anaconda environment errors that prevent model training typically fall into a few categories: dependency conflicts between packages, CUDA/GPU driver mismatches, incompatible Python versions, and corrupted environments. The fix is usually to create a clean conda environment with pinned versions of your ML framework (TensorFlow, PyTorch, scikit-learn), verify GPU drivers, and avoid mixing pip and conda installs. This article covers the most common Anaconda training errors and their solutions.
Dependency Conflicts
The most common issue — packages require different versions of the same dependency:
1# Error example
2ERROR: pip's dependency resolver does not currently take into account
3all the packages that are installed. The following packages have
4incompatible dependencies:
5 tensorflow 2.15 requires numpy<2.0,>=1.23; python_version >= "3.9"
6 pandas 2.1 requires numpy>=1.23.2
7
8# Fix: create a fresh environment with compatible versions
9conda create -n ml python=3.10 -y
10conda activate ml
11conda install tensorflow=2.15 pandas numpy=1.26 -c conda-forge
Check for conflicts:
1# List installed packages and versions
2conda list
3
4# Check for dependency issues
5pip check
6
7# Show specific package dependencies
8conda info tensorflow
CUDA and GPU Driver Errors
1# Error: Could not load dynamic library 'libcudart.so.12'
2# Error: CUDA driver version is insufficient for CUDA runtime version
3
4# Check CUDA version
5nvidia-smi # Shows driver version and max CUDA version
6nvcc --version # Shows installed CUDA toolkit version
7
8# Install matching CUDA toolkit via conda
9conda install cudatoolkit=11.8 cudnn=8.6 -c conda-forge
10
11# For PyTorch with specific CUDA
12conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
13
14# For TensorFlow
15pip install tensorflow[and-cuda] # TF 2.15+ auto-installs CUDA
Environment Setup Best Practices
1# Create isolated environment
2conda create -n training python=3.10 -y
3conda activate training
4
5# Install ML framework first (it sets compatible dependencies)
6conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
7# OR
8conda install tensorflow -c conda-forge
9
10# Then install other packages
11conda install pandas scikit-learn matplotlib jupyter -c conda-forge
12
13# Export for reproducibility
14conda env export > environment.yml
15
16# Recreate from file
17conda env create -f environment.yml
Fixing a Corrupted Environment
1# Option 1: Remove and recreate
2conda deactivate
3conda env remove -n ml
4conda create -n ml python=3.10 -y
5
6# Option 2: Clean conda cache
7conda clean --all
8
9# Option 3: Reset packages
10conda activate ml
11conda install --revision 0 # Revert to initial state
Common Error Messages and Fixes
"ModuleNotFoundError: No module named 'tensorflow'"
1# Package installed in a different environment
2conda activate ml # Make sure correct environment is active
3which python # Verify it points to the conda environment
4pip install tensorflow # Install in the active environment
"ImportError: cannot import name 'xxx' from 'keras'"
1# TF 2.x changed Keras imports
2# Before: from keras.models import Sequential
3# After: from tensorflow.keras.models import Sequential
4
5# Or standalone Keras (Keras 3+)
6pip install keras
7from keras.models import Sequential
"OOM when allocating tensor"
1# GPU out of memory — limit memory growth
2import tensorflow as tf
3gpus = tf.config.experimental.list_physical_devices('GPU')
4for gpu in gpus:
5 tf.config.experimental.set_memory_growth(gpu, True)
6
7# Or limit memory
8tf.config.set_logical_device_configuration(
9 gpus[0],
10 [tf.config.LogicalDeviceConfiguration(memory_limit=4096)]
11)
"Mixed pip and conda packages"
1# Avoid mixing pip and conda for the same package
2# If you must use pip, install conda packages first
3conda install numpy scipy pandas # conda first
4pip install some-pip-only-package # pip after
5
6# Check for conflicts
7pip check
Verifying the Setup
1# verify_setup.py
2import sys
3print(f"Python: {sys.version}")
4print(f"Executable: {sys.executable}")
5
6try:
7 import tensorflow as tf
8 print(f"TensorFlow: {tf.__version__}")
9 print(f"GPU available: {tf.config.list_physical_devices('GPU')}")
10except ImportError:
11 print("TensorFlow not installed")
12
13try:
14 import torch
15 print(f"PyTorch: {torch.__version__}")
16 print(f"CUDA available: {torch.cuda.is_available()}")
17 if torch.cuda.is_available():
18 print(f"CUDA device: {torch.cuda.get_device_name(0)}")
19except ImportError:
20 print("PyTorch not installed")
21
22import numpy as np
23print(f"NumPy: {np.__version__}")
conda activate ml
python verify_setup.py
Common Pitfalls
Mixing pip install and conda install for the same package: Installing TensorFlow with pip and then NumPy with conda (or vice versa) can create incompatible binary versions. Use one package manager consistently — prefer conda for ML packages that need compiled dependencies.
Not creating a dedicated environment: Installing ML packages in the base environment leads to dependency conflicts with system packages. Always create a new environment with conda create -n myenv python=3.10 for each project.
CUDA toolkit version mismatch: The CUDA version must match what your ML framework was compiled against. Check the framework's documentation for supported CUDA versions — for example, TensorFlow 2.15 requires CUDA 12.2, not 11.8.
Using Python 3.12+ with frameworks that do not support it yet: Some ML packages lag behind Python releases. TensorFlow and PyTorch may not have wheels for the latest Python version. Use Python 3.10 or 3.11 for maximum compatibility.
Not running conda clean --all after failed installs: Failed installations leave cached packages that can interfere with subsequent installs. Run conda clean --all to clear the cache before retrying.
Summary
Create a dedicated conda environment for each ML project — never install in base
Install the ML framework first (TensorFlow or PyTorch) to set compatible dependency versions
Use nvidia-smi and nvcc --version to verify GPU driver and CUDA toolkit compatibility
Avoid mixing pip and conda for the same package — use one manager consistently
Use pip check and conda list to diagnose dependency conflicts
Export environments with conda env export > environment.yml for reproducibility