uploadcare / pillow-simd

The friendly PIL fork
https://python-pillow.github.io/pillow-perf/
Other
2.12k stars 85 forks source link

Cannot install on apple silicon (aarch64): "gcc: error: unrecognized command-line option ‘-msse4’" #116

Closed sopoforic closed 1 year ago

sopoforic commented 1 year ago

What did you do?

I added Pillow-SIMD==9.0.0.post1 to my requirements.txt, which is to be installed in a docker container running python:3.10.5-slim.

What did you expect to happen?

Pillow-simd should have been installed.

What actually happened?

On x86_64, this works correctly. But on apple silicon, it fails with:

#11 20.85       building 'PIL._imaging' extension
#11 20.85       creating build/temp.linux-aarch64-3.10
#11 20.85       creating build/temp.linux-aarch64-3.10/src
#11 20.85       creating build/temp.linux-aarch64-3.10/src/libImaging
#11 20.85       building 'PIL._imagingtk' extension
#11 20.85       creating build/temp.linux-aarch64-3.10/src/Tk
#11 20.85       gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/pyenv/include -I/usr/local/include -I/usr/include -I/pyenv/include -I/usr/local/include/python3.10 -c src/Tk/tkImaging.c -o build/temp.linux-aarch64-3.10/src/Tk/tkImaging.o
#11 20.85       building 'PIL._imagingmath' extension
#11 20.85       gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/pyenv/include -I/usr/local/include -I/usr/include -I/pyenv/include -I/usr/local/include/python3.10 -c src/_imagingmath.c -o build/temp.linux-aarch64-3.10/src/_imagingmath.o
#11 20.85       gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DHAVE_LIBJPEG -DHAVE_LIBZ -DPILLOW_VERSION="9.0.0.post1" -I/pyenv/include -I/usr/local/include -I/usr/include -I/pyenv/include -I/usr/local/include/python3.10 -c src/_imaging.c -o build/temp.linux-aarch64-3.10/src/_imaging.o -msse4
#11 20.85       building 'PIL._imagingmorph' extension
#11 20.85       gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/pyenv/include -I/usr/local/include -I/usr/include -I/pyenv/include -I/usr/local/include/python3.10 -c src/_imagingmorph.c -o build/temp.linux-aarch64-3.10/src/_imagingmorph.o
#11 20.85       gcc: error: unrecognized command-line option ‘-msse4’
#11 20.85       gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/pyenv/include -I/usr/local/include -I/usr/include -I/pyenv/include -I/usr/local/include/python3.10 -c src/_imagingtk.c -o build/temp.linux-aarch64-3.10/src/_imagingtk.o
#11 20.85       gcc -pthread -shared -Wl,--strip-all build/temp.linux-aarch64-3.10/src/_imagingmorph.o -L/pyenv/lib -L/usr/lib/aarch64-linux-gnu -L/lib/aarch64-linux-gnu -L/usr/local/lib -L/lib -L/usr/lib -L/usr/local/lib -o build/lib.linux-aarch64-3.10/PIL/_imagingmorph.cpython-310-aarch64-linux-gnu.so
#11 20.85       gcc -pthread -shared -Wl,--strip-all build/temp.linux-aarch64-3.10/src/Tk/tkImaging.o build/temp.linux-aarch64-3.10/src/_imagingtk.o -L/pyenv/lib -L/usr/lib/aarch64-linux-gnu -L/lib/aarch64-linux-gnu -L/usr/local/lib -L/lib -L/usr/lib -L/usr/local/lib -o build/lib.linux-aarch64-3.10/PIL/_imagingtk.cpython-310-aarch64-linux-gnu.so
#11 20.85       gcc -pthread -shared -Wl,--strip-all build/temp.linux-aarch64-3.10/src/_imagingmath.o -L/pyenv/lib -L/usr/lib/aarch64-linux-gnu -L/lib/aarch64-linux-gnu -L/usr/local/lib -L/lib -L/usr/lib -L/usr/local/lib -o build/lib.linux-aarch64-3.10/PIL/_imagingmath.cpython-310-aarch64-linux-gnu.so
#11 20.85       error: command '/usr/bin/gcc' failed with exit code 1
#11 20.85       [end of output]
#11 20.85   
#11 20.85   note: This error originates from a subprocess, and is likely not a problem with pip.
#11 20.86 error: legacy-install-failure
#11 20.86 
#11 20.86 × Encountered error while trying to install package.
#11 20.86 ╰─> Pillow-SIMD
#11 20.86 
#11 20.86 note: This is an issue with the package mentioned above, not pip.
#11 20.86 hint: See above for output from the failure.

NB: wheel is installed already, but it attempts to build anyway.

What are your OS, Python and Pillow versions?

sopoforic commented 1 year ago

Can you explain why you closed this? Did I miss something in the documentation and do something wrong? I would expect this to compile without any optimizations if there are none available, or anyway to do something other than give a bad command line to gcc.

homm commented 1 year ago

Currently, Pillow-SIMD can be compiled with SSE4 (default) or AVX2 support.

This means only x86 and x86-64 architectures are supported. Apple m1 is a different architecture, called ARM. Pillow-SIMD code is extreme platform-specific and there is no easy way to compile it under ARM. So this is not an issue, it is just not what you are looking for. Please, use standard Pillow instead of Pillow-SIMD.

sopoforic commented 1 year ago

Sure, that's what I did--I wrote it in conditionally in the requirements.txt depending on the architecture, because not all developers are using the same machines. I just expected that if pillow-simd was a "100% compatible drop-in replacement" then on architectures that don't support the optimizations, it would fall back to the same behavior as pillow. Perhaps this isn't practical.