ImportError: libjpeg.so.8: cannot open shared object file: No such file or directory
Fixes ImportError: libjpeg.so.8: cannot open shared object file: No such file or directory Use when Pillow import or JPEG open fails on libjpeg.so.8 missing (WSL, Docker, minimal images) Not for: Pillow not installed at all
How to fix ImportError: libjpeg.so.8: cannot open shared object file: No such file or directory
The system JPEG library Pillow was built against is missing. On Debian/Ubuntu: sudo apt-get install libjpeg-turbo8 (or libjpeg8). Easiest robust fix: reinstall Pillow from a wheel so it bundles its own libs: pip install --force-reinstall --no-cache-dir pillow.
The exact error
ImportError: libjpeg.so.8: cannot open shared object file: No such file or directoryFix it
sudo apt-get install libjpeg-turbo8(Debian/Ubuntu) or the equivalent libjpeg package.
Expected: libjpeg.so.8 exists on the system
- Or reinstall Pillow as a wheel:
pip install --force-reinstall --no-cache-dir pillow.
Expected: Pillow bundles its own libs
- Verify: open a JPEG with PIL and call .load() on it.
Expected: image loads, prints ok
When this applies
Pillow import or JPEG open fails on libjpeg.so.8 missing (WSL, Docker, minimal images)
When this does NOT apply
Pillow not installed at all
Versions
Linux, Pillow built from source / minimal envs
Why it happens
Source-built Pillow links the system libjpeg; the runtime image lacks it.
Edge cases
Alpine/musl needs the apk libjpeg-turbo package; prefer musl wheels when available.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.