High severity beginner · Fix: 2-5 min

ModuleNotFoundError

ModuleNotFoundError: No module named 'bitsandbytes'

What this error means
This error occurs because the bitsandbytes library, required for QLoRA quantization, is not installed or not found in the Python environment.

Stack trace

traceback
Traceback (most recent call last):
  File "train_qlora.py", line 10, in <module>
    import bitsandbytes as bnb
ModuleNotFoundError: No module named 'bitsandbytes'
QUICK FIX
Run 'pip install bitsandbytes' in your environment to install the missing library immediately.

Why it happens

QLoRA relies on the bitsandbytes library for 4-bit quantization and efficient GPU memory usage. If bitsandbytes is not installed or incompatible with your environment, Python raises a ModuleNotFoundError when importing it.

Detection

Check for ModuleNotFoundError exceptions referencing 'bitsandbytes' during your QLoRA training script startup or import phase.

Causes & fixes

1

bitsandbytes library is not installed in the current Python environment

✓ Fix

Install bitsandbytes via pip using 'pip install bitsandbytes' or 'pip install bitsandbytes-cudaXXX' matching your CUDA version.

2

bitsandbytes installed but incompatible CUDA version or missing GPU drivers

✓ Fix

Ensure bitsandbytes version matches your CUDA toolkit version and GPU drivers are up to date; reinstall bitsandbytes with the correct CUDA wheel.

3

Running in an environment without GPU support or unsupported OS

✓ Fix

Use CPU-only fallback or switch to a supported GPU environment; bitsandbytes requires compatible GPU hardware and drivers.

Code: broken vs fixed

Broken - triggers the error
python
import os
import bitsandbytes as bnb  # ModuleNotFoundError here if bitsandbytes not installed

# QLoRA training code continues...
Fixed - works correctly
python
import os
import bitsandbytes as bnb  # Fixed by installing bitsandbytes via pip

# QLoRA training code continues...
Installed bitsandbytes library so the import succeeds, enabling QLoRA quantization features.

Workaround

If you cannot install bitsandbytes now, disable QLoRA or switch to a non-quantized training mode that does not require bitsandbytes.

Prevention

Add bitsandbytes to your project's requirements.txt or environment setup scripts and verify CUDA compatibility before deployment to avoid missing dependency errors.

Python 3.8+ · bitsandbytes >=0.37.0 · tested on 0.39.0
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.