chroma-core/chroma · error · ValueError

The torch python package is not installed. Please install it

Error message

The torch python package is not installed. Please install it with `pip install torch`

What it means

After the open_clip import, OpenCLIPEmbeddingFunction.__init__ imports torch via importlib and raises ValueError with a pip hint on ImportError. open_clip is a thin wrapper around PyTorch models, so torch is a hard runtime requirement; `pip install open-clip-torch` normally pulls torch in, so seeing this error alone usually means the dependency was stripped or installed into the wrong environment (or a deliberately torch-free slim image).

Source

Thrown at chromadb/utils/embedding_functions/open_clip_embedding_function.py:51

        Args:
            model_name (str, optional): The name of the model to use for embeddings.
                Defaults to "ViT-B-32".
            checkpoint (str, optional): The checkpoint to use for the model.
                Defaults to "laion2b_s34b_b79k".
            device (str, optional): The device to use for computation.
                Defaults to "cpu".
        """
        try:
            import open_clip
        except ImportError:
            raise ValueError(
                "The open_clip python package is not installed. Please install it with `pip install open-clip-torch`. https://github.com/mlfoundations/open_clip"
            )

        try:
            self._torch = importlib.import_module("torch")
        except ImportError:
            raise ValueError(
                "The torch python package is not installed. Please install it with `pip install torch`"
            )

        try:
            self._PILImage = importlib.import_module("PIL.Image")
        except ImportError:
            raise ValueError(
                "The PIL python package is not installed. Please install it with `pip install pillow`"
            )

        self.model_name = model_name
        self.checkpoint = checkpoint
        self.device = device

        model, _, preprocess = open_clip.create_model_and_transforms(
            model_name=model_name, pretrained=checkpoint
        )
        self._model = model

View on GitHub (pinned to aecdd12c8a)

Solutions

  1. pip install torch (choose the right wheel for your platform/CUDA from pytorch.org, e.g. pip install torch --index-url https://download.pytorch.org/whl/cpu for CPU-only)
  2. Prefer installing torch first and then open-clip-torch so pip doesn't resolve a mismatched torch version
  3. Verify: python -c "import torch; print(torch.__version__, torch.cuda.is_available())"

Example fix

// before
fn = OpenCLIPEmbeddingFunction()  # ValueError: torch not installed

// after (shell, CPU example)
pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install open-clip-torch
// then
fn = OpenCLIPEmbeddingFunction()
Defensive patterns

Strategy: validation

Validate before calling

import importlib.util
if importlib.util.find_spec("torch") is None:
    raise SystemExit("torch missing: install the right wheel from pytorch.org (CPU: pip install torch --index-url https://download.pytorch.org/whl/cpu)")

Try / catch

try:
    fn = OpenCLIPEmbeddingFunction()
except ValueError as e:
    if "torch" in str(e):
        raise SystemExit("Run: pip install torch (see pytorch.org for CUDA/CPU wheels)") from e
    raise

Prevention

When it happens

Trigger: Constructing OpenCLIPEmbeddingFunction() in an image built with `pip install open-clip-torch --no-deps`; torch uninstalled later to save space; a CPU/GPU torch install failure (wheel download is ~2GB and frequently times out) that left open-clip-torch present but torch absent; conda/pip environment mixing.

Common situations: Slim production images removing the huge torch wheel; CI artifact caching that skipped the torch layer; torch install interrupted by network limits; Apple Silicon machines needing the special-preview wheel and failing silently.

Related errors


AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16). Data as JSON: /api/errors/d43a356778540de4. Report an issue: GitHub.