Repository: python-pillow/Pillow

Issue:
Build fails under Cygwin with Python 3.9.16 and false "jpeg not found" message
<!--
Thank you for reporting an issue.

Follow these guidelines to ensure your issue is handled properly.

If you have a ...

1.  General question: consider asking the question on Stack Overflow
    with the python-imaging-library tag:

    * https://stackoverflow.com/questions/tagged/python-imaging-library

    Do not ask a question in both places.

    If you think you have found a bug or have an unexplained exception
    then file a bug report here.

2.  Bug report: include a self-contained, copy-pastable example that
    generates the issue if possible. Be concise with code posted.
    Guidelines on how to provide a good bug report:

    * https://stackoverflow.com/help/mcve

    Bug reports which follow these guidelines are easier to diagnose,
    and are often handled much more quickly.

3.  Feature request: do a quick search of existing issues
    to make sure this has not been asked before.

We know asking good questions takes effort, and we appreciate your time.
Thank you.
-->

### What did you do?

Tried to install Pillow via pip ```pip install Pillow```

Then tried to git clone and install via ```pip install -e .``` from latest source in a fresh and clean virtual environment

### What did you expect to happen?

Clean download, compile and install

### What actually happened?

install errored out:

    The headers or library files could not be found for jpeg,
    a required dependency when compiling Pillow from source.

### Potentially related issues:

* #553 
* #560 
* #1201 
* #1690 
* #2860
* #3181 
* #3581
* #5191 
* #5795 
* #6216 
* #7066 

### What are your OS, Python and Pillow versions?

* OS: windows 10, Cygwin (latest update from today, 2023-05-11)
* Python: 3.9.16
* Pillow: 1.7.6-14728-g8874549a9

## Full Python version:

    $ Python
    Python 3.9.16 (main, Mar  8 2023, 22:47:22)
    [GCC 11.3.0] on cygwin

## Potentially relevant Cygwin package versions:

    cygwin    3.4.6-1
    cygwin-devel    3.4.6-1
    base-cygwin    3.8-2
    gcc-g++    11.3.0-1
    python-pip-wheel    19.2.3-1
    python-setuptools-wheel    0.37.1-1
    python3    3.9.10-1
    python3-devel    3.9.10-1
    python39    3.9.16-1
    python39-cython    0.29.33-1
    python39-devel    3.9.16-1
    python39-packaging    21.3-1
    python39-pkgconfig    1.5.5.-1
    python39-setuptools    67.6.0-1
    python39-virtualenv    20.21.0-1
    python39-wheel    0.38.4-1
    python39-imaging    8.4.0-1
    pkg-config    1.9.5-1
    pkgconf    1.9.5-1
    jpeg    2.1.5.1-1
    libjpeg-devel    2.1.5.1-1
    libjpeg8    2.1.5.1-1
    libopenjpeg-devel    1.5.2-3
    libopenjpeg1    1.5.2-3
    openjpeg    1.5.2-3
    openjpeg2    2.5.0-1
    zlib-devel    1.2.13-1
    zlib0    1.2.13-1
    libtiff6    4.4.0-1
    libtiff7    4.5.0-1
    libfreetype6    2.13.0-1
    liblcms2_2    2.15-1
    libwebp7    1.3.0-1
    libimagequant0    2.10.0-1
    libraqm0    0.7.0-1

<!--
Please include **code** that reproduces the issue and whenever possible, an **image** that demonstrates the issue. Please upload images to GitHub, not to third-party file hosting sites. If necessary, add the image to a zip or tar archive.

The best reproductions are self-contained scripts with minimal dependencies. If you are using a framework such as Plone, Django, or Buildout, try to replicate the issue just using Pillow.
-->

### Steps to reproduce

See also script below.
* Setup a minimal Cygwin environment with packages as listed above.
* Create a virtual python environment ```virtualenv-3.9  pillow-tst```
* Activate virtual environment.  Within run ```pip install pillow```

## Script try-build-pillow.sh:
```bash
#! /bin/bash

stamp="$(date +%Y-%m-%d_%H%M%S)"
base="pillow-tmp"
full="${base}_${stamp}"

virtualenv-3.9 "${full}"
pushd "${full}" || exit 1
. bin/activate
pip --version
python --version
pip install pillow
popd
```

## Script output
```
 ./try-build-pillow.sh
created virtual environment CPython3.9.16.final.0-64 in 2512ms
  creator CPython3Posix(dest=/home/bak/pillow-tmp_2023-05-11_155517, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/bak/.local/share/virtualenv)
    added seed packages: pip==23.0.1, setuptools==67.6.1, wheel==0.40.0
  activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
~/pillow-tmp_2023-05-11_155517 ~
pip 23.0.1 from /home/bak/pillow-tmp_2023-05-11_155517/lib/python3.9/site-packages/pip (python 3.9)
Python 3.9.16
Collecting pillow
  Using cached Pillow-9.5.0.tar.gz (50.5 MB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: pillow
  Building wheel for pillow (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [189 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.cygwin-3.4.6-x86_64-cpython-39
      creating build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/BdfFontFile.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/BlpImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/BmpImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/BufrStubImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/ContainerIO.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/CurImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/DcxImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/DdsImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/EpsImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/ExifTags.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/features.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/FitsImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/FitsStubImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/FliImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/FontFile.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/FpxImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/FtexImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/GbrImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/GdImageFile.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/GifImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/GimpGradientFile.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/GimpPaletteFile.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/GribStubImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/Hdf5StubImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/IcnsImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/IcoImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/Image.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/ImageChops.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/ImageCms.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/ImageColor.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/ImageDraw.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/ImageDraw2.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/ImageEnhance.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/ImageFile.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/ImageFilter.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/ImageFont.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/ImageGrab.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/ImageMath.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/ImageMode.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/ImageMorph.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/ImageOps.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/ImagePalette.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/ImagePath.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/ImageQt.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/ImageSequence.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/ImageShow.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/ImageStat.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/ImageTk.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/ImageTransform.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/ImageWin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/ImImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/ImtImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/IptcImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/Jpeg2KImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/JpegImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/JpegPresets.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/McIdasImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/MicImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/MpegImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/MpoImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/MspImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/PaletteFile.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/PalmImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/PcdImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/PcfFontFile.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/PcxImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/PdfImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/PdfParser.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/PixarImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/PngImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/PpmImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/PsdImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/PSDraw.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/PyAccess.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/QoiImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/SgiImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/SpiderImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/SunImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/TarIO.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/TgaImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/TiffImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/TiffTags.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/WalImageFile.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/WebPImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/WmfImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/XbmImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/XpmImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/XVThumbImagePlugin.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/_binary.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/_deprecate.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/_tkinter_finder.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/_util.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/_version.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/__init__.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      copying src/PIL/__main__.py -> build/lib.cygwin-3.4.6-x86_64-cpython-39/PIL
      running egg_info
      writing src/Pillow.egg-info/PKG-INFO
      writing dependency_links to src/Pillow.egg-info/dependency_links.txt
      writing requirements to src/Pillow.egg-info/requires.txt
      writing top-level names to src/Pillow.egg-info/top_level.txt
      reading manifest file 'src/Pillow.egg-info/SOURCES.txt'
      reading manifest template 'MANIFEST.in'
      warning: no files found matching '*.c'
      warning: no files found matching '*.h'
      warning: no files found matching '*.sh'
      warning: no files found matching '*.txt'
      warning: no previously-included files found matching '.appveyor.yml'
      warning: no previously-included files found matching '.clang-format'
      warning: no previously-included files found matching '.coveragerc'
      warning: no previously-included files found matching '.editorconfig'
      warning: no previously-included files found matching '.readthedocs.yml'
      warning: no previously-included files found matching 'codecov.yml'
      warning: no previously-included files found matching 'renovate.json'
      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
      no previously-included directories found matching '.ci'
      adding license file 'LICENSE'
      writing manifest file 'src/Pillow.egg-info/SOURCES.txt'
      running build_ext


      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

      Traceback (most recent call last):
        File "/tmp/pip-install-2bvhmusu/pillow_2fb74b21c9a04782b3dade7d8d874d33/setup.py", line 993, in <module>
          setup(
        File "/home/bak/pillow-tmp_2023-05-11_155517/lib/python3.9/site-packages/setuptools/__init__.py", line 108, in setup
          return distutils.core.setup(**attrs)
        File "/home/bak/pillow-tmp_2023-05-11_155517/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 185, in setup
          return run_commands(dist)
        File "/home/bak/pillow-tmp_2023-05-11_155517/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
          dist.run_commands()
        File "/home/bak/pillow-tmp_2023-05-11_155517/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
          self.run_command(cmd)
        File "/home/bak/pillow-tmp_2023-05-11_155517/lib/python3.9/site-packages/setuptools/dist.py", line 1221, in run_command
          super().run_command(command)
        File "/home/bak/pillow-tmp_2023-05-11_155517/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/home/bak/pillow-tmp_2023-05-11_155517/lib/python3.9/site-packages/wheel/bdist_wheel.py", line 343, in run
          self.run_command("build")
        File "/home/bak/pillow-tmp_2023-05-11_155517/lib/python3.9/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
          self.distribution.run_command(command)
        File "/home/bak/pillow-tmp_2023-05-11_155517/lib/python3.9/site-packages/setuptools/dist.py", line 1221, in run_command
          super().run_command(command)
        File "/home/bak/pillow-tmp_2023-05-11_155517/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/home/bak/pillow-tmp_2023-05-11_155517/lib/python3.9/site-packages/setuptools/_distutils/command/build.py", line 131, in run
          self.run_command(cmd_name)
        File "/home/bak/pillow-tmp_2023-05-11_155517/lib/python3.9/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
          self.distribution.run_command(command)
        File "/home/bak/pillow-tmp_2023-05-11_155517/lib/python3.9/site-packages/setuptools/dist.py", line 1221, in run_command
          super().run_command(command)
        File "/home/bak/pillow-tmp_2023-05-11_155517/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/home/bak/pillow-tmp_2023-05-11_155517/lib/python3.9/site-packages/setuptools/command/build_ext.py", line 84, in run
          _build_ext.run(self)
        File "/home/bak/pillow-tmp_2023-05-11_155517/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py", line 345, in run
          self.build_extensions()
        File "/tmp/pip-install-2bvhmusu/pillow_2fb74b21c9a04782b3dade7d8d874d33/setup.py", line 809, in build_extensions
          raise RequiredDependencyException(f)
      __main__.RequiredDependencyException: jpeg

      During handling of the above exception, another exception occurred:

      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-2bvhmusu/pillow_2fb74b21c9a04782b3dade7d8d874d33/setup.py", line 1010, in <module>
          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


      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pillow
  Running setup.py clean for pillow
Failed to build pillow
Installing collected packages: pillow
  Running setup.py install for pillow ... error
  error: subprocess-exited-with-error

 [ similar output from setup install step cut ]
````

# Actual available libraries:
```shell
$ find /usr/lib /lib -name '*jpeg*'
/usr/lib/gdk-pixbuf-2.0/2.10.0/loaders/cygpixbufloader-jpeg.dll
/usr/lib/libjpeg.dll.a
/usr/lib/libopenjpeg.dll.a
/usr/lib/openjpeg-1.5
/usr/lib/pkgconfig/libjpeg.pc
/usr/lib/pkgconfig/libopenjpeg.pc
/usr/lib/qt5/plugins/imageformats/cygqjpeg.dll
/lib/gdk-pixbuf-2.0/2.10.0/loaders/cygpixbufloader-jpeg.dll
/lib/libjpeg.dll.a
/lib/libopenjpeg.dll.a
/lib/openjpeg-1.5
/lib/pkgconfig/libjpeg.pc
/lib/pkgconfig/libopenjpeg.pc
/lib/pkgconfig/libopenjpeg1.pc
/lib/qt5/plugins/imageformats/cygqjpeg.dll

$ find /usr /lib -name jpeglib.h
/usr/include/jpeglib.h
```


Feel free to contact me (@ mention) if you need further information.



Discussion:
@ipa-bak Cygwin may be tough, because I'm not sure if it _ever_ worked well enough to rely on, but maybe. I may be able to test on Windows 11 if that would help. [WSL](https://learn.microsoft.com/en-us/windows/wsl/install) may be worth checking out too.
We currently test Cygwin as one of our CI jobs - https://github.com/python-pillow/Pillow/blob/main/.github/workflows/test-cygwin.yml

https://github.com/python-pillow/Pillow/issues/6216#issuecomment-1122340162
> https://github.com/pypa/distutils/pull/139 has merged a fix into upstream of setuptools, so that fix should be propagating into setuptools in time.
>
> For anyone who needs a fix before then and cannot downgrade to setuptools<60, setting an environment variable SETUPTOOLS_USE_DISTUTILS=stdlib should allow the patches in the Cygwin python packages to handle this case, and I think that environment variable will stick around until setuptools upgrades its bundled distutils.

If I remove `SETUPTOOLS_USE_DISTUTILS=stdlib` from our CI job, I get your error, so I would try prefixing your install command with that.
I can confirm that adding ```SETUPTOOLS_USE_DISTUTILS=stdlib``` solved the problem and I could successfully install Pillow.  Thanks @radarhere for the suggestion!

You can close the issue or keep it for reference until setuptools work again without that setting.
Thanks @radarhere ! Regularly testing Cygwin on GH Actions since 2021™, awesome. https://github.com/python-pillow/Pillow/actions/workflows/test-cygwin.yml
@DWesl I would have thought that https://github.com/pypa/distutils/pull/139 became https://github.com/pypa/setuptools/commit/c6f28fcc19fec4a4db2d663cb34240baa740f63b, and so would have been included in setuptools 62.4.0.

Do you have any idea why `SETUPTOOLS_USE_DISTUTILS=stdlib` is still needed?
I don't need that when building locally, so my guess is that virtualenv installs an old version of setuptools.  Does this script work better?
```bash
stamp="$(date +%Y-%m-%d_%H%M%S)"
base="pillow-tmp"
full="${base}_${stamp}"

virtualenv-3.9 "${full}"
pushd "${full}" || exit 1
. bin/activate
pip --version
python --version
pip install 'setuptools>=62.4.0'
pip install pillow
popd
```
If I [stop using `SETUPTOOLS_USE_DISTUTILS=stdlib`](https://github.com/radarhere/Pillow/commit/9a3ed619e885f51e5e2bec300d5af40f33411fcc) on GitHub Actions, it [fails](https://github.com/radarhere/Pillow/actions/runs/4968623392/jobs/8891330429#step:11:195).

If I [print the setuptools version](https://github.com/radarhere/Pillow/commit/95ac663d57172ae0c5652e57fdb1928ff79f20c5), I get [67.6.0](https://github.com/radarhere/Pillow/actions/runs/4968761768/jobs/8891554012#step:10:55). Interestingly, I also find that it uses [UnixCCompiler](https://github.com/radarhere/Pillow/actions/runs/4968761768/jobs/8891554012#step:10:56), which [might actually be correct](https://github.com/pypa/setuptools/blob/e76db4408e40a5c0a218ef6f652454f69c5aca59/setuptools/_distutils/ccompiler.py#L1056), but your changes in https://github.com/pypa/distutils/pull/139 were to the Cygwin compiler?
I made pypa/distutils#209 to make the same changes in `UnixCCompiler` that pypa/distutils#139 made to `CygwinCCompiler`; hopefully that fixes this problem.
[Testing](https://github.com/radarhere/Pillow/commit/1ae1b52246da8f9a5344f815cb961adf1620ba44), I find that [it does](https://github.com/radarhere/Pillow/actions/runs/4972268392)! Thanks very much.
@DWesl although I don't know much about the distutils (not to say: nothing 😄 ) , it seems strange that under Cygwin the rules from ```UnixCCompiler``` are used and not those from ```CygwinCCompiler```.  Maybe there is something else wrong?
@DWesl ["on a cygwin built python we can use gcc like an ordinary UNIXish"](https://github.com/pypa/setuptools/blob/e76db4408e40a5c0a218ef6f652454f69c5aca59/setuptools/_distutils/ccompiler.py#L1056)

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -515,6 +515,7 @@ def build_extensions(self):
 
         elif sys.platform == "cygwin":
             # pythonX.Y.dll.a is in the /usr/lib/pythonX.Y/config directory
+            self.compiler.shared_lib_extension = ".dll.a"
             _add_directory(
                 library_dirs,
                 os.path.join(


Test patch: