OSError: libm.so.6: version `GLIBC_2.27' not found
Resolves torch GLIBC version failures via OS/container/pin options. Use when the error names GLIBC_X.XX not found under torch libs. Not for a missing torch install.
TL;DR: Upgrade your OS/glibc or use an older torch. New torch wheels need a newer glibc than old distros (CentOS 7, Ubuntu 18.04) ship. Your options: upgrade the OS, use a container with a newer base image, or pin torch to a version built for your glibc (torch 1.13 works on manylinux2014-era systems).
The error:
OSError: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by /.../torch/lib/libtorch_cpu.so)Fix
Check:
ldd --versionExpected: shows your glibc; 2.27+ needed for current torchEasiest: run in a container, e.g.
docker run --gpus all -it pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtimeExpected: import torch works insideOr pin older torch:
python -m pip install 'torch==1.13.1' --index-url https://download.pytorch.org/whl/cpuExpected: imports on old glibc
When this applies
- GLIBC_X.XX not found required by torch libs
- import torch failing on old Linux distros
When this does not apply
- No module named 'torch' (not installed)
- other missing .so errors (different libs)
Version compatibility
torch 2.x needs glibc >= 2.28 or so (manylinux228 wheels); torch 1.13 targets manylinux2014.
Why it happens
PyTorch's wheels are built against recent manylinux standards. Old distros ship older glibc, and the dynamic loader refuses to load libtorch when the required symbol versions are absent.
Edge cases
- Upgrading the OS is the durable fix; pinning old torch accrues tech debt.
- Conda's torch sometimes bundles more compat; worth a try before downgrading.
- Do not replace system libm; you will break the OS.