No such file or directory "limits.h" when installing Pillow on Alpine Linux
To swiftly resolve the "limits.h" missing file error on Alpine Linux, execute the following command:
The build-base
package is a compilation of essential developer tools, including the GCC compiler (gcc
), libraries, and headers (libc-dev
). These provide necessary files like limits.h
, a key element for compiling Python packages like Pillow.
Understanding the issue and the solution
Alpine Linux is unique in its use of musl libc, which differs from the more common glibc used by many other Linux distributions. The musl-dev package supplies development resources for musl libc, including headers like limits.h
.
When you install Pillow, it attempts to compile certain native extensions that require these particular headers. Therefore, installing the musl-dev
package is necessary.
Typically, installing build-base
covers all requirements. But, if you need to be more explicit with your packages, consider installing the following:
Here, python3-dev
includes header files for Python development, while libc-dev
and linux-headers
supply general C development headers. This combination ensures a more comprehensive range of development files, covering not just Pillow but other Python packages with similar necessities.
Efficiency hacks: --no-cache
While installing packages, apk add
offers a --no-cache
shortcut, a simple yet effective way to save precious disk space by preventing package caching:
This option is particularly advantageous in space-limited environments like Docker containers.
Up-to-date prerequisite tools
Before building Pillow, ensure your pip
and setuptools
are current. In several instances, problems with package building can be resolved just by updating these tools:
Compatibility-aware installation
If you're working with Docker or Raspberry Pi, acknowledge that Alpine packages may offer greater compatibility and stability over their pip counterparts. This is primarily due to the musl libc dependencies:
Remember to double-check the case sensibility and correct naming while dealing with package installations.
A proactive approach: Checking for dependencies
Package installations can fail due to missing dependencies. Always check the full list of dependencies for your package, which might include certain developer libraries or specific versions of other packages.
Was this article helpful?