Repository: python-pillow/Pillow

Issue:
zlib requirement on Alpine Linux
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?



Discussion:
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.

@wiredfool 
https://pkgs.alpinelinux.org/contents?branch=v3.3&name=zlib-dev&arch=x86_64&repo=main

@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.


Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -405,6 +405,8 @@ def build_extensions(self):
 
             _add_directory(library_dirs, "/usr/lib")
             _add_directory(include_dirs, "/usr/include")
+            # alpine, at least
+            _add_directory(library_dirs, "/lib")
 
         # on Windows, look for the OpenJPEG libraries in the location that
         # the official installer puts them
@@ -789,8 +791,11 @@ def add_multiarch_paths(self):
         if not os.path.exists(self.build_temp):
             os.makedirs(self.build_temp)
         with open(tmpfile, 'wb') as fp:
-            ret = subprocess.call([
-                'dpkg-architecture', '-qDEB_HOST_MULTIARCH'], stdout=fp)
+            try:
+                ret = subprocess.call(['dpkg-architecture',
+                                       '-qDEB_HOST_MULTIARCH'], stdout=fp)
+            except:
+                return
         try:
             if ret >> 8 == 0:
                 fp = open(tmpfile, 'r')


Test patch: