Repository: python-pillow/Pillow

Issue:
Can't install Pillow on Android
### What did you do?

I'm running Python on Android (with Termux).
I'm trying to install Pillow by running `pip install Pillow`.
### What did you expect to happen?

Install Pillow.
### What actually happened?

```
Collecting Pillow
  Using cached Pillow-3.2.0.zip
Installing collected packages: Pillow
  Running setup.py install for Pillow ... error
    Complete output from command /data/data/com.termux/files/usr/bin/python -u -c "import setuptools, tokenize;__file__='/data/data/com.termux/files/usr/tmp/pip-build-ufp_l0v2/Pillow/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /data/data/com.termux/files/usr/tmp/pip-403p6uq1-record/install-record.txt --single-version-externally-managed --compile:
    Exception installing mp_compile, proceeding without:This platform lacks a functioning sem_open implementation, therefore, the required synchronization primitives needed will not function, see issue 3770.
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-armv7l-3.5
    creating build/lib.linux-armv7l-3.5/PIL
    copying PIL/ImageGrab.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/TiffImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/MicImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/FitsStubImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/ExifTags.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/ImageChops.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/CurImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/ImageEnhance.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/WebPImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/PngImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/DcxImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/TgaImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/PsdImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/JpegPresets.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/GimpPaletteFile.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/GbrImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/OleFileIO.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/PSDraw.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/_binary.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/ImageSequence.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/DdsImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/McIdasImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/IptcImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/ImageTransform.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/PdfImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/JpegImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/FontFile.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/Hdf5StubImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/PcxImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/WalImageFile.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/ImageQt.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/ImageFile.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/IcnsImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/BufrStubImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/EpsImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/TiffTags.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/BmpImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/MpoImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/GimpGradientFile.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/SgiImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/ImageCms.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/ImageDraw2.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/ImageStat.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/SpiderImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/ImageWin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/Jpeg2KImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/__init__.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/ImagePalette.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/FtexImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/Image.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/SunImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/ImageFont.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/ImageTk.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/TarIO.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/ImageShow.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/PpmImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/XpmImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/ImageColor.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/PyAccess.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/GifImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/ImagePath.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/ImageFilter.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/ImageMode.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/features.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/GdImageFile.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/ContainerIO.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/MspImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/PalmImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/ImageMath.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/FliImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/MpegImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/PcfFontFile.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/XbmImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/ImageOps.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/ImageDraw.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/PixarImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/BdfFontFile.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/FpxImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/ImImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/IcoImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/ImtImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/PcdImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/PaletteFile.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/_util.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/ImageMorph.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/XVThumbImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/WmfImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    copying PIL/GribStubImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
    running egg_info
    writing dependency_links to Pillow.egg-info/dependency_links.txt
    writing top-level names to Pillow.egg-info/top_level.txt
    writing Pillow.egg-info/PKG-INFO
    warning: manifest_maker: standard file '-c' not found

    reading manifest file 'Pillow.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    warning: no files found matching '*.sh'
    no previously-included directories found matching 'docs/_static'
    warning: no previously-included files found matching '.coveragerc'
    warning: no previously-included files found matching '.editorconfig'
    warning: no previously-included files found matching '.landscape.yaml'
    warning: no previously-included files found matching 'appveyor.yml'
    warning: no previously-included files found matching 'build_children.sh'
    warning: no previously-included files found matching 'tox.ini'
    warning: no previously-included files matching '.git*' found anywhere in distribution
    warning: no previously-included files matching '*.pyc' found anywhere in distribution
    warning: no previously-included files matching '*.so' found anywhere in distribution
    writing manifest file 'Pillow.egg-info/SOURCES.txt'
    copying PIL/OleFileIO-README.md -> build/lib.linux-armv7l-3.5/PIL
    running build_ext
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/data/data/com.termux/files/usr/tmp/pip-build-ufp_l0v2/Pillow/setup.py", line 767, in <module>
        zip_safe=not debug_build(), )
      File "/data/data/com.termux/files/usr/lib/python3.5/distutils/core.py", line 148, in setup
        dist.run_commands()
      File "/data/data/com.termux/files/usr/lib/python3.5/distutils/dist.py", line 955, in run_commands
        self.run_command(cmd)
      File "/data/data/com.termux/files/usr/lib/python3.5/distutils/dist.py", line 974, in run_command
        cmd_obj.run()
      File "/data/data/com.termux/files/usr/lib/python3.5/site-packages/setuptools/command/install.py", line 61, in run
        return orig.install.run(self)
      File "/data/data/com.termux/files/usr/lib/python3.5/distutils/command/install.py", line 539, in run
        self.run_command('build')
      File "/data/data/com.termux/files/usr/lib/python3.5/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/data/data/com.termux/files/usr/lib/python3.5/distutils/dist.py", line 974, in run_command
        cmd_obj.run()
      File "/data/data/com.termux/files/usr/lib/python3.5/distutils/command/build.py", line 135, in run
        self.run_command(cmd_name)
      File "/data/data/com.termux/files/usr/lib/python3.5/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/data/data/com.termux/files/usr/lib/python3.5/distutils/dist.py", line 974, in run_command
        cmd_obj.run()
      File "/data/data/com.termux/files/usr/lib/python3.5/distutils/command/build_ext.py", line 338, in run
        self.build_extensions()
      File "/data/data/com.termux/files/usr/tmp/pip-build-ufp_l0v2/Pillow/setup.py", line 512, in build_extensions
        ' using --disable-%s, aborting' % (f, f))
    ValueError: zlib is required unless explicitly disabled using --disable-zlib, aborting

    ----------------------------------------
Command "/data/data/com.termux/files/usr/bin/python -u -c "import setuptools, tokenize;__file__='/data/data/com.termux/files/usr/tmp/pip-build-ufp_l0v2/Pillow/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /data/data/com.termux/files/usr/tmp/pip-403p6uq1-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /data/data/com.termux/files/usr/tmp/pip-build-ufp_l0v2/Pillow/
```
### What versions of Pillow and Python are you using?

I'm running Python 3.5.1. I'm trying to install Pillow 3.2.0.

From what I understand, zlib is already included in Android so I shouldn't need to install it.



Discussion:
You need to have the headers for the libraries as well, and more importantly, Pillow has to be able to find them. I'm not aware of Pillow being built for Android before, so it's entirely possible that the libraries/headers are not in the usual places. 

There's a reasonable amount of information about how to install in the documentation, you're going to be in the building from source on linux section.

I do have the headers at `/data/data/com.termux/files/usr/include/zlib.h` but it does not find them even if I specify the path manually with `CFLAGS="-I/data/data/com.termux/files/usr/include/" pip install Pillow`.
Everything else seems to build correctly if I do `python setup.py build_ext --disable-zlib`

Then it's not finding the library. You should try installing from master, with `python setup.py build_ext --debug`, which will show where it's looking for libraries and headers. 

You were right, it was not looking in the right directory.
I had to run with `LDFLAGS="-L/system/lib/"` and it worked.
Thanks for your help!

I have the same problem.
but I did not understand how to solve.

I installed it like this:

``` bash
LDFLAGS="-L/system/lib/" pip install Pillow
```

 sorry. I'm starting developer. 
I'm in this directory /data/data/com.termux/files/usr/lib/python3.5/site-packages
insert string LDFLAGS = "- L / system / lib /" pip install Pillow
but I get the same error

> Воскресенье,  7 августа 2016, 21:11 +04:00 от Pierre Rudloff notifications@github.com:
> 
> I installed it like this:
> LDFLAGS="-L/system/lib/" pip install Pillow
> —
> You are receiving this because you commented.
> Reply to this email directly,  view it on GitHub , or  mute the thread .

In my case, I had to install Pillow using the following command:
`LDFLAGS="-L/system/lib/ -lm -lcompiler_rt" pip2 install Pillow --global-option="build_ext" --global-option="--disable-jpeg"`
For this to work, you'll need to `apt install python2-dev` first, if you haven't installed it already.
Notes:
1. This solution is for Python 2.x; YMMV for Python 3.
2. You won't get jpeg support when installing Pillow this way
Also, note that you don't really need to `--disable-jpeg` (which disables JPEG support). You can just `apt install libjpeg-turbo-dev` (or `openjpeg-dev`), and it should be good to go :)
After trying a lot of solutions, the one which works for me was
`LDFLAGS="-L/system/lib/" CFLAGS="-I/data/data/com.termux/files/usr/include/" pip install Pillow`

But I don't know yet if it's only due to it or caused by a combination... Anyway if it can help!
I don't have "/data/data/com.termux/files/usr/include/zlib.h" on my Zenfone 2.
Is that possible to install Pillow on a Zenfone 2?
@biazzotto I think you need to install the `ndk-sysroot` package in Termux.

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -365,6 +365,14 @@ def build_extensions(self):
                 # work ;-)
                 self.add_multiarch_paths()
 
+                # termux support for android.
+                # system libraries (zlib) are installed in /system/lib
+                # headers are at $PREFIX/include
+                # user libs are at $PREFIX/lib
+                if os.environ.get('ANDROID_ROOT', None):
+                    _add_directory(library_dirs,
+                                  os.path.join(os.environ['ANDROID_ROOT'],'lib'))
+
         elif sys.platform.startswith("gnu"):
             self.add_multiarch_paths()
 


Test patch: