python-pillow / Pillow

Python Imaging Library (Fork)
https://python-pillow.org
Other
11.8k stars 2.13k forks source link

Unable to install Pillow on M1 Mac (Clang error) #8035

Closed niekvandepas closed 1 month ago

niekvandepas commented 1 month ago

What did you do?

I ran pip install Pillow.

What did you expect to happen?

I expected pip to install Pillow.

What actually happened?

I got a compilation error:

Collecting pillow
  Using cached pillow-10.3.0.tar.gz (46.6 MB)
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
  Installing backend dependencies: started
  Installing backend dependencies: finished with status 'done'
  Preparing metadata (pyproject.toml): started
  Preparing metadata (pyproject.toml): finished with status 'done'
Building wheels for collected packages: pillow
  Building wheel for pillow (pyproject.toml): started
  Building wheel for pillow (pyproject.toml): finished with status 'error'
  error: subprocess-exited-with-error

  × Building wheel for pillow (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [18953 lines of output]

[snip]

      error: command '/opt/homebrew/opt/llvm@12/bin/clang' failed with exit code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pillow
Failed to build pillow
ERROR: Could not build wheels for pillow, which is required to install pyproject.toml-based projects

Digging through the clang output, I mostly see a bunch of warnings (not errors) of the form warning: unknown platform 'visionos' in availability macro [-Wavailability]. I tried to grep for err or fatal but couldn't find anything in the output, which I've uploaded as a Gist here.

Command-line tools for macOS are installed properly, and I'm able to build other Pip packages.

What are your OS, Python and Pillow versions?

aclark4life commented 1 month ago

Can you try pip install -U pip then try again? Seems like pip should be choosing one of the arm64 wheels here: https://pypi.org/project/pillow/10.3.0/#files but instead it's falling back to compilation, which then fails.

niekvandepas commented 1 month ago

Thanks for checking in.

> pip install -U pip
Requirement already satisfied: pip in /Users/niekvdpas/.pyenv/versions/3.10.14/lib/python3.10/site-packages (24.0)

> pip install pillow
[same result]

No luck unfortunately.

Trying to install the arm64 wheel manually gives me the following error:

> python3 -m pip install ./pillow-10.3.0-pp310-pypy310_pp73-macosx_11_0_arm64.whl
ERROR: pillow-10.3.0-pp310-pypy310_pp73-macosx_11_0_arm64.whl is not a supported wheel on this platform.

EDIT: same goes for attempting to install the arm64 CPython wheel:

> python3 --version
Python 3.10.14
> python3 -m pip install ./pillow-10.3.0-cp310-cp310-macosx_11_0_arm64.whl
ERROR: pillow-10.3.0-cp310-cp310-macosx_11_0_arm64.whl is not a supported wheel on this platform.
hugovk commented 1 month ago

Please could you try reinstalling with -vv for extra debug output? It will tell us which wheels it attempted and why it skipped them.

And also run pip debug --verbose to show your compatible tags.

hugovk commented 1 month ago

And what does python --version --version say?

niekvandepas commented 1 month ago

Output of python --version --version:

Python 3.10.14 (main, Apr 25 2024, 10:24:02) [Clang 12.0.1 ]

Output of pip debug --verbose.

Output of pip install pillow -vv.

radarhere commented 1 month ago

https://github.com/python-pillow/Pillow/issues/6725 was a previous post with the same initial error. That user's guess about what happened was that there was a

misformed dependency tree in homebrew. Maybe related to llvm installed through homebrew which broke z3 lib for clang

Their solution was to

reinstalled xcode, python (via brew), pyenv and finally was able to get Pillow installed

I'm not saying you need to do anything so drastic, but it's something to think about at least.

radarhere commented 1 month ago

For a slightly odd idea, since pip debug --verbose lists "cp310-cp310-macosx_10_16_arm64", and 10.16 and 11.0 are the same thing, you could download pillow-10.3.0-cp310-cp310-macosx_11_0_arm64.whl, rename it to pillow-10.3.0-cp310-cp310-macosx_10_16_arm64.whl, and try installing that.

radarhere commented 1 month ago

https://github.com/pypa/pip/issues/11789 talks about a faliure to find macOS 11 wheels with Python 3.8, and the problem seems to be outdated packaging.

Could you pip install --upgrade packaging and then try installing Pillow again?

niekvandepas commented 1 month ago

Thanks for the help! The renaming trick worked :)

Upgrading packaging did not seem to do anything, unfortunately.

niekvandepas commented 1 month ago

Hang on, I'm now getting an error when trying to import:

import pytesseract
from PIL import Image
Traceback (most recent call last):
  File "/Users/niekvdpas/code/ocr.py", line 1, in <module>
    import pytesseract
  File "/Users/niekvdpas/.pyenv/versions/3.10.14/lib/python3.10/site-packages/pytesseract/__init__.py", line 2, in <module>
    from .pytesseract import ALTONotSupported
  File "/Users/niekvdpas/.pyenv/versions/3.10.14/lib/python3.10/site-packages/pytesseract/pytesseract.py", line 27, in <module>
    from PIL import Image
  File "/Users/niekvdpas/.pyenv/versions/3.10.14/lib/python3.10/site-packages/PIL/Image.py", line 94, in <module>
    from . import _imaging as core
ImportError: cannot import name '_imaging' from 'PIL' (/Users/niekvdpas/.pyenv/versions/3.10.14/lib/python3.10/site-packages/PIL/__init__.py)

Seems like the installation may not have been as succesful as it seemed

radarhere commented 1 month ago

Given your multiple attempts at installation, could you pip uninstall Pillow, make sure you can't import Pillow at all (if not, uninstall again), and then try installing from the renamed wheel again?

niekvandepas commented 1 month ago

Ah, that fixed it! Thanks so much!