{"record":{"id":"d43a356778540de4","repo":"chroma-core/chroma","slug":"the-torch-python-package-is-not-installed-please","errorCode":null,"errorMessage":"The torch python package is not installed. Please install it with `pip install torch`","messagePattern":"The torch python package is not installed\\. Please install it with `pip install torch`","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/open_clip_embedding_function.py","lineNumber":51,"sourceCode":"        Args:\n            model_name (str, optional): The name of the model to use for embeddings.\n                Defaults to \"ViT-B-32\".\n            checkpoint (str, optional): The checkpoint to use for the model.\n                Defaults to \"laion2b_s34b_b79k\".\n            device (str, optional): The device to use for computation.\n                Defaults to \"cpu\".\n        \"\"\"\n        try:\n            import open_clip\n        except ImportError:\n            raise ValueError(\n                \"The open_clip python package is not installed. Please install it with `pip install open-clip-torch`. https://github.com/mlfoundations/open_clip\"\n            )\n\n        try:\n            self._torch = importlib.import_module(\"torch\")\n        except ImportError:\n            raise ValueError(\n                \"The torch python package is not installed. Please install it with `pip install torch`\"\n            )\n\n        try:\n            self._PILImage = importlib.import_module(\"PIL.Image\")\n        except ImportError:\n            raise ValueError(\n                \"The PIL python package is not installed. Please install it with `pip install pillow`\"\n            )\n\n        self.model_name = model_name\n        self.checkpoint = checkpoint\n        self.device = device\n\n        model, _, preprocess = open_clip.create_model_and_transforms(\n            model_name=model_name, pretrained=checkpoint\n        )\n        self._model = model","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/open_clip_embedding_function.py#L33-L69","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["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)","Prefer installing torch first and then open-clip-torch so pip doesn't resolve a mismatched torch version","Verify: python -c \"import torch; print(torch.__version__, torch.cuda.is_available())\""],"exampleFix":"// before\nfn = OpenCLIPEmbeddingFunction()  # ValueError: torch not installed\n\n// after (shell, CPU example)\npip install torch --index-url https://download.pytorch.org/whl/cpu\npip install open-clip-torch\n// then\nfn = OpenCLIPEmbeddingFunction()","handlingStrategy":"validation","validationCode":"import importlib.util\nif importlib.util.find_spec(\"torch\") is None:\n    raise SystemExit(\"torch missing: install the right wheel from pytorch.org (CPU: pip install torch --index-url https://download.pytorch.org/whl/cpu)\")","typeGuard":null,"tryCatchPattern":"try:\n    fn = OpenCLIPEmbeddingFunction()\nexcept ValueError as e:\n    if \"torch\" in str(e):\n        raise SystemExit(\"Run: pip install torch (see pytorch.org for CUDA/CPU wheels)\") from e\n    raise","preventionTips":["Install torch first (correct variant for CPU/CUDA), then open-clip-torch, to avoid resolver surprises","The torch wheel is ~2GB — use deterministic, retryable build steps and layer caching in Docker","Don't build slim images by removing torch if any CLIP embedding is used"],"tags":["openclip","torch","embedding-function","import-error","dependency","chroma"],"backgroundTag":"missing-dependency","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}