title: "The headers or library files could not be found for jpeg" installing Pillow on Alpine Linux
body: <p>I'm trying to run Python's Scrapy in a Docker container based on <a href="https://hub.docker.com/_/python/" rel="noreferrer">python:alpine</a>. It was working before, but now I'd like to use Scrapy's <a href="https://doc.scrapy.org/en/latest/topics/media-pipeline.html#using-the-images-pipeline" rel="noreferrer">Image Pipeline</a> which requires me to install Pillow.</p>
  
  <p>As a simplified example, I tried the following <code>Dockerfile</code>:</p>
  
  <pre><code>FROM python:alpine
  RUN apk --update add libxml2-dev libxslt-dev libffi-dev gcc musl-dev libgcc openssl-dev curl
  RUN apk add libjpeg zlib tiff freetype lcms libwebp tcl openjpeg
  RUN pip install Pillow
  </code></pre>
  
  <p>However, when I try to build this I get an error which contains the following:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/tmp/pip-build-ft5yzzuv/Pillow/setup.py", line 744, in &lt;module&gt;
      zip_safe=not debug_build(), )
    File "/usr/local/lib/python3.6/distutils/core.py", line 148, in setup
      dist.run_commands()
    File "/usr/local/lib/python3.6/distutils/dist.py", line 955, in run_commands
      self.run_command(cmd)
    File "/usr/local/lib/python3.6/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/usr/local/lib/python3.6/site-packages/setuptools/command/install.py", line 61, in run
      return orig.install.run(self)
    File "/usr/local/lib/python3.6/distutils/command/install.py", line 545, in run
      self.run_command('build')
    File "/usr/local/lib/python3.6/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/usr/local/lib/python3.6/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/usr/local/lib/python3.6/distutils/command/build.py", line 135, in run
      self.run_command(cmd_name)
    File "/usr/local/lib/python3.6/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/usr/local/lib/python3.6/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/usr/local/lib/python3.6/distutils/command/build_ext.py", line 339, in run
      self.build_extensions()
    File "/tmp/pip-build-ft5yzzuv/Pillow/setup.py", line 545, in build_extensions
      raise RequiredDependencyException(f)
  __main__.RequiredDependencyException: jpeg
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "&lt;string&gt;", line 1, in &lt;module&gt;
    File "/tmp/pip-build-ft5yzzuv/Pillow/setup.py", line 756, in &lt;module&gt;
      raise RequiredDependencyException(msg)
  __main__.RequiredDependencyException:
  
  The headers or library files could not be found for jpeg,
  a required dependency when compiling Pillow from source.
  
  Please see the install instructions at:
     https://pillow.readthedocs.io/en/latest/installation.html
  </code></pre>
  
  <p>I went through the requirements on <a href="https://pillow.readthedocs.io/en/latest/installation.html" rel="noreferrer">https://pillow.readthedocs.io/en/latest/installation.html</a> and tried to find the corresponding packages for Alpine, although one I couldn't find was <strong>libimagequant</strong>, so this might be the 'culprit'. Nonetheless, it the traceback and error message seem to be saying that <code>jpeg</code> is missing, whereas I have installed <code>openjpeg</code>. </p>
  
  <p>How can I modify the <code>Dockerfile</code> so that <code>pip install Pillow</code> runs?</p>