zlib requirement on Alpine Linux
mattchen opened this issue ยท 16 comments
hey, I was trying to install Pillow on Alpine Linux 3.3 official docker container by "pip install pillow", but I get this error:
ValueError: --enable-zlib requested but zlib not found, aborting.
I have installed all the zlib library as I know, zlib-dev, libzip-dev by "apk add", and I checked /usr/include/libzip.h, which is 1.2.8, I'm not sure if there's something wrong with the library file or filename.
UPDATE: After I copied /lib/libz.so and /lib/libz.a to /usr/lib/ (which is installed by default), the installation has finished successfully. Guess /lib/ should be in the library check list?
The library it's looking for is zlib and zlib.h. libzip is something else (zip archives).
It looks like we're not actually looking in /lib on linux machines since most of the distros have shifted to multiarch library paths. It's certainly possible to add it by setting the environment variables C_INCLUDE_PATH/CPATH/INCLUDE and LD_RUN_PATH/LIBRARY_PATH/LIB.
(It's also possible that one of those paths has been added from the python config, which may be why /usr/lib works on Alpine)
And as an aside, that error should have been `'%s is required unless explicitly disabled using --disable-%s, aborting', but the feature name is spelled incorrectly.
@wiredfool Thanks. I was having the same problem building a docker image, but was able to get it to build by putting these lines above any pip install statements in my Dockerfile:
RUN apk add build-base python-dev py-pip jpeg-dev zlib-dev
ENV LIBRARY_PATH=/lib:/usr/lib
Where does Alpine store the headers? It's got to be somewhere pretty standard or it wouldn't build.
The official zlib-dev package in Alpine has the headers stored in /lib/. See the package contents here:
https://pkgs.alpinelinux.org/contents?pkgname=zlib-dev&arch=x86_64&repo=main
Thanks, that page was down when I was checking originally, Looks like /usr/include (already checked by defaultt), with the libraries in /lib.
@halfspiral
You oftentimes want to keep docker layers flat, or don't want to clutter env with some temporary variables. So you would need to pack those environment declaration somewhere inline. For future googlers, here is how it goes:
LIBRARY_PATH=/lib:/usr/lib /bin/sh -c "pip install -r /requirements.txt"
Note: you need to call pip via a new shell to have the variable take effect.
Out of curiosity is anyone building and publishing wheels for Pillow for the Alpine Docker platform?
@prologic I'm planning to do this for pandas and few other packages, please join discussion at pypa/manylinux#37
just apk add jpeg-dev zlib-dev in my case
Thanks to @ghost
Are jpeg-dev zlib-dev
only build dependencies or do I need them in future for usage?
Asking because surprisingly my application worked even after removing them after installation was complete. :-)
just apk add jpeg-dev zlib-dev in my case
Thanks to @ghost
RUN apk add jpeg-dev zlib-dev
RUN LIBRARY_PATH=/lib:/usr/lib /bin/sh -c "pip install --install-option="--prefix=/build" -r /requirements.txt"
Showing error - unable to execute 'gcc': No such file or directory
@wiredfool Thanks. I was having the same problem building a docker image, but was able to get it to build by putting these lines above any pip install statements in my Dockerfile:
RUN apk add build-base python-dev py-pip jpeg-dev zlib-dev ENV LIBRARY_PATH=/lib:/usr/lib
RUN apk add build-base python-dev py-pip jpeg-dev zlib-dev
RUN LIBRARY_PATH=/lib:/usr/lib /bin/sh -c "pip install --install-option="--prefix=/build" -r /requirements.txt"
Error -
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -I/usr/local/include/python3.7m -c bcrypt/bcrypt_python.c -o build/temp.linux-x86_64-3.7/bcrypt/bcrypt_python.o
bcrypt/bcrypt_python.c:31:26: error: unknown type name 'u_int8_t'; did you mean 'uint8_t'?
void encode_salt(char *, u_int8_t *, u_int16_t, u_int8_t);
^~~~~~~~
uint8_t
bcrypt/bcrypt_python.c:31:38: error: unknown type name 'u_int16_t'; did you mean 'uint16_t'?
void encode_salt(char *, u_int8_t *, u_int16_t, u_int8_t);
^~~~~~~~~
uint16_t
bcrypt/bcrypt_python.c:31:49: error: unknown type name 'u_int8_t'; did you mean 'uint8_t'?
void encode_salt(char *, u_int8_t *, u_int16_t, u_int8_t);
^~~~~~~~
uint8_t
bcrypt/bcrypt_python.c: In function 'bcrypt_encode_salt':
bcrypt/bcrypt_python.c:58:5: warning: implicit declaration of function 'encode_salt' [-Wimplicit-function-declaration]
encode_salt(ret, (u_int8_t *) csalt, csaltlen, log_rounds);
^~~~~~~~~~~
bcrypt/bcrypt_python.c:58:23: error: 'u_int8_t' undeclared (first use in this function); did you mean 'uint8_t'?
encode_salt(ret, (u_int8_t *) csalt, csaltlen, log_rounds);
^~~~~~~~
uint8_t
bcrypt/bcrypt_python.c:58:23: note: each undeclared identifier is reported only once for each function it appears in
bcrypt/bcrypt_python.c:58:33: error: expected expression before ')' token
encode_salt(ret, (u_int8_t *) csalt, csaltlen, log_rounds);
^
error: command 'gcc' failed with exit status 1
EDIT : installing musl-dev solved the problem.
Note: for Alpine 9.3.0
, the Python dev package is python3-dev
, not python-dev
, e.g.,
apk add python3-dev