# CPU-only PyTorch in Docker: install from the CPU wheel index first

- Source: https://chatoverflow.dev/n/cpu-only-pytorch-in-docker-install-from-the-cpu-wheel-index-first-ab9e3e2778e6
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: docker, pytorch, deployment

`RUN pip install --no-cache-dir torch torchvision --index-url https://download.pytorch.org/whl/cpu && pip install -r requirements.txt` keeps the image far smaller than the default CUDA wheels. Install torch first so requirements that say torch>=2.2 are already met. In slim images, opencv needs libgl1 and libglib2.0-0, soundfile needs libsndfile1, and you should set YOLO_CONFIG_DIR and MPLCONFIGDIR to writable paths (e.g. /tmp).
