Closed HarshSonawane closed 3 years ago
First off, any particular reason to use Pillow 7.2.0 on not 8.x? Python 3.9 support was officially added to Pillow in 8.0.0:
https://pillow.readthedocs.io/en/stable/installation.html#python-support
I think there's still some work going on in the packaging world to support Apple silicon, and so it's attempting to install and build from source.
Please could you first try after updating pip and wheel?
It's also possible to download one of the wheels from https://pypi.org/project/Pillow/8.0.1/#files and change one of the tags in the filename, and pip install
that, but I can't find the details for that now. It was something like replace x86_64
with universal2
.
Or to build from source, you need to install some dependencies first:
The headers or library files could not be found for zlib,
a required dependency when compiling Pillow from source.
Please see the install instructions at:
https://pillow.readthedocs.io/en/latest/installation.html
Thank you for reaching back. I have also tried with pillow version 8.0.1 but the same issue is going on, unable to install Pillow.
I have same question I try execute
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow
on the Macbook Pro 13 M1 Silicon have the same question on the Macbook Air Intel Core is Successfully
@jia611 Please can you try this? (Instructions based on https://github.com/scipy/scipy/issues/13102#issuecomment-733988544)
$ python3 -m pip install packaging
$ python3 -c"from packaging import tags; print('\n'.join([str(t) for t in tags.sys_tags()]))" |head -5
cp38-cp38-macosx_11_0_x86_64
2. Download 8.0.1 wheel from PyPI https://pypi.org/project/Pillow/8.0.1/#files
3. Rename downloaded file to match your tag
```sh
mv Pillow-8.0.1-cp38-cp38-macosx_10_10_x86_64.whl Pillow-8.0.1-cp38-cp38-macosx_11_0_x86_64.whl
python3 -m pip install Pillow-8.0.1-cp38-cp38-macosx_11_0_x86_64.whl
Or https://github.com/scipy/scipy/issues/13102#issuecomment-744473479:
Fwiw, I managed to install
scipy
on Big Sur (Intel Macbook) by using the compatibility mode, in which macOS will report being version 10.16 instead of 11.0:export SYSTEM_VERSION_COMPAT=1 > sw_vers -productVersion 10.16
python3 -m pip install Pillow-8.0.1-cp38-cp38-macosx_11_0_x86_64.whl is error
ERROR: Pillow-8.0.1-cp38-cp38-macosx_11_0_x86_64.whl is not a supported wheel on this platform.
@jia611 What output do you get for this?
python3 -c"from packaging import tags; print('\n'.join([str(t) for t in tags.sys_tags()]))" |head -5
@jia611 What output do you get for this?
python3 -c"from packaging import tags; print('\n'.join([str(t) for t in tags.sys_tags()]))" |head -5
cp38-cp38-macosx_11_0_arm64 cp38-cp38-macosx_11_0_universal2 cp38-abi3-macosx_11_0_arm64 cp38-abi3-macosx_11_0_universal2 cp38-none-macosx_11_0_arm64
Then please try renaming it to match one of those, for example Pillow-8.0.1-cp38-cp38-macosx_11_0_universal2.whl
Perhaps an obvious answer to be had. If I download and change to Pillow-8.0.1-cp38-cp38-macosx_11_0_universal2.whl
where do I put the file to actually run sudo python3 -m pip install Pillow-8.0.1-cp38-cp38-macosx_11_0_universal2.whl
?
In your current directory.
Or you could change the command to use a relative path.
Or, you could specify an absolute path, e.g. sudo python3 -m pip install /Users/geoffsharris/Downloads/Pillow-8.0.1-cp38-cp38-macosx_11_0_universal2.whl
Then please try renaming it to match one of those, for example
Pillow-8.0.1-cp38-cp38-macosx_11_0_universal2.whl
thank you Successfully installed Pillow-8.0.1
Good to hear, thanks for testing!
Now the question is what changes do we need to make for the next release to be pip installable on M1 from PyPI? Are changes needed at multibuild? I think pip+packaging (https://github.com/pypa/packaging/pull/319) and wheel (https://github.com/pypa/wheel/pull/390) are ready.
The installation worked on my Macbook Pro 13 M1 but when I try to use it still has problems. I am trying to run the https://github.com/tensorflow/hub/blob/master/examples/colab/object_detection.ipynb notebook.
I get the following error: dlopen(python3.8/site-packages/PIL/_imaging.cpython-38-darwin.so, 2): no suitable image found. Did find: tensorflow_venv/lib/python3.8/site-packages/PIL/_imaging.cpython-38-darwin.so: mach-o, but wrong architecture
@goleador how did you install Pillow?
@radarhere I have the same problem as @goleador
when i run python3 in arm arch,python3 main.py ,error log is:
from PIL import Image, ImageDraw, ImageFont, ImageFilter
File "/Users/tx/Work/dykt_back/venv/lib/python3.9/site-packages/PIL/Image.py", line 94, in <module>
from . import _imaging as core
ImportError: dlopen(/Users/tx/Work/dykt_back/venv/lib/python3.9/site-packages/PIL/_imaging.cpython-39-darwin.so, 2): no suitable image found. Did find:
/Users/tx/Work/dykt_back/venv/lib/python3.9/site-packages/PIL/_imaging.cpython-39-darwin.so: mach-o, but wrong architecture
/Users/tx/Work/dykt_back/venv/lib/python3.9/site-packages/PIL/_imaging.cpython-39-darwin.so: mach-o, but wrong architecture
and when i run arch -x86_64 python3 main.py , the service is successful.
I installed using the directions on this thread. Basically, renaming the .whl file as described above. @radarhere
In case this is helpful to anyone, here's a wheel I put together on my M1 - Pillow-8.0.1-cp39-cp39-macosx_11_0_arm64.whl.zip
@radarhere Tried to install your wheel on my m1.
Got :
ERROR: Pillow-8.0.1-cp39-cp39-macosx_11_0_arm64.whl is not a supported wheel on this platform.
.
:(
@y4nng-dev were you using Python 3.9, or a different Python version? Could you provide the full command that you used to try and install the wheel?
@radarhere I'm using Python 3.8.2 and here is the command I used :
python3 -m pip install /Users/username/Desktop/Pillow-8.0.1-cp39-cp39-macosx_11_0_arm64.whl
Thank you
@y4nng-dev ah, yes - the wheel I attached was for Python 3.9. Here is a wheel for Python 3.8 - Pillow-8.0.1-cp38-cp38-macosx_11_0_arm64.whl.zip
thank you
Now the question is what changes do we need to make for the next release to be pip installable on M1 from PyPI? Are changes needed at multibuild? I think pip+packaging (pypa/packaging#319) and wheel (pypa/wheel#390) are ready.
https://github.com/actions/virtual-environments/issues/1814 is in preview, and https://github.com/actions/runner/issues/805 is also pending. I've created https://github.com/matthew-brett/multibuild/pull/379 as a start in multibuild at least.
Create a virtual environment using venv and then try to use pip to install. It didn't work when I tried it the first time but then i used brew install libjpeg and then i tried pip then it worked.
So in your case it must have built from source, and we don't have any matching prebuilt binary wheels.
It would be nice to have binary wheels for the universal2 build of Python 3.9.1 on www.python.org, that would take away the need to build from source (which is finicky when you don't use homebrew)
Do note that support for universal2 wheels in the packaging space is very new, to the point that AFAIK the currently released version of pip won't install binary wheels with a platform tag that matches the above mentioned universal2 python. That should should resolve itself once my PR for the packaging library makes it way to a release of pip.
Yes, that would be best.
https://github.com/pypa/packaging/pull/380 was merged 5 days ago, so should be vendored in the next pip 21.0, due out on 23/34 January, give or take a week (https://github.com/pypa/pip/issues/9282#issuecomment-753301504).
On the Pillow side, what do we actually need to do build universal2 binary wheels? Are changes needed in https://github.com/python-pillow/pillow-wheels or https://github.com/matthew-brett/multibuild?
I haven't checked the two repos you mention, but there shouldn't be many changes.
I build Pillow and jpegsrc-6b from source before filing this issue and that didn't need any changes other than specifying "-arch arm64 -arch x86_64" when building the latter. That said, I haven't tested the intel part of the wheel yet (but I don't expect problems there, given past experience with the ppc to intel transition).
The main gotcha w.r.t. building universal2 wheels at the moment is that you need to build on a macOS 11 system because the sysconfig module currently assumes that compilers on older versions of the OS cannot build arm64 binaries. That's something I intent to fix and that change will hopefully be in 3.9.2.
Okay, obviously I'm missing something here.
(testing) dist % pip install psycopg2-2.9.dev0-cp38-cp38-macosx_10_14_arm64.whl
ERROR: psycopg2-2.9.dev0-cp38-cp38-macosx_10_14_arm64.whl is not a supported wheel on this platform.
From a comment from Pillow:
_I build Pillow and jpegsrc-6b from source before filing this issue and that didn't need any changes other than specifying "-arch arm64 -arch x8664" when building the latter. That said, I haven't tested the intel part of the wheel yet (but I don't expect problems there, given past experience with the ppc to intel transition).
So I probably need to change the target build architecture, but I don't see where to do that... ?
The problem you're seeing with pip is a buglet in pip (or rather packaging), PR 350 for packaging fixes that and will end up in a future release (AFAIK later this month).
There are more moving parts in the packaging space than I had expected beforehand, because of that I have spent too little time on the packaging ecosystem before the "universal2" changes ended up in a Python release.
Please feel free to let me know if there is anything that I can do to assist, testing, etc.
@radarhere
Trying to understand the build process here, how do you specify the architecture when running an package/wheel creation?
I just run a standard python setup.py sdist bdist_wheel?
I haven't found any documentation that builds a specific arch? So I'm a bit confused....
@bschollnick I wasn't specifying the architecture - I was just building wheels on an M1 machine. It would have been python setup.py bdist_wheel
and then delocate to bundle in the libraries - python delocate/cmd/delocate_wheel.py dist/Pillow-8.2.0.dev0-cp38-cp38-macosx_11_0_arm64.whl
@bschollnick you can see over at https://github.com/python-pillow/Pillow-wheels, where we generate the Linux and macOS wheels for each release, that we're just spinning up Linux and macOS instances and building the wheel on each of them.
@bschollnick you'll probably be interested in https://github.com/matthew-brett/multibuild/pull/383
Hi! So, is there any workaround to make pillow work on M1? I don't have much experience building wheels. To be honest im not even sure what is a wheel but if there is a solution to this issue I would be more than happy to know about it. Many thanks!
Hi. I presume you have tried to install Pillow, but are getting an error like 'The headers or library files could not be found for zlib, a required dependency when compiling Pillow from source.' Pillow is complaining that you are missing zlib, one of its dependencies.
pip install Pillow
then it would have searched for an environment-appropriate wheel, but failed to find one.
pip install [filename.whl]
, that should also work for you.To be clear, building wheels is not something that you do to help install a Python module on your computer, it's something that you do so that you can distribute the wheel and help other people install Pillow.
@liuchanganshan Why use Python 3.9.1 release candidate 1 and not the Python 3.9.1 production release?
macOS 64-bit Intel installer | Mac OS X | for macOS 10.9 and later | 74f5cc5b5783ce8fb2ca55f11f3f0699 | 29795899 | SIG choose this version is ok. arm64version not ok @cclauss
Why choose macOS 64-bit Intel installer
when you are on ARM64, not Intel?
m1-macbook-pro ~ % python3
Python 3.9.1 (default, Jan 8 2021, 12:11:08)
[Clang 12.0.0 (clang-1200.0.32.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform ; platform.processor()
'arm'
Did you try going to https://www.python.org/downloads and clicking the button Download Python 3.9.1
?
Alternatively, brew install python
will also install Python 3.9.1.
Here are some notes to compile Pillow from source with libjpeg support on M1 using arm64 architecture:
curl -L -O http://ijg.org/files/jpegsrc.v9d.tar.gz
tar -xvf jpegsrc.v9d.tar.gz
cd jpeg-9d
./configure CFLAGS="-arch arm64" CXXFLAGS="-arch arm64" LDFLAGS="-arch arm64
make
sudo make install
Note: here you need sudo
to install it to /usr/local
, however, you can specify where to install libJPEG by using --prefix=/dir in the ./configure command.
To check if your libJEPG is compiled with arm64 architecture
lipo -info /usr/local/lib/libjpeg.dylib
You will see something like this
Non-fat file: /usr/local/lib/libjpeg.dylib is architecture: arm64
Get Pillow-8.1.0 from pypi:
curl -L -O https://files.pythonhosted.org/packages/73/59/3192bb3bc554ccbd678bdb32993928cb566dccf32f65dac65ac7e89eb311/Pillow-8.1.0.tar.gz
tar -xvf Pillow-8.1.0.tar.gz
cd Pillow-8.1.0
Add the following lines after line 493 in setup.py, which tells the compiler to use -arch arm64 on Apple's M1 Arm Chip:
import platform
if platform.machine() == 'arm64':
os.environ["ARCHFLAGS"] = "-arch arm64"
It will look like this:
Save the setup.py. Then you can build and install it:
python3 setup.py build
python3 setup.py install --user
or
python3 setup.py build
sudo python3 setup.py install
Check the Pillow architecture:
% lipo -info _imaging.cpython-38-darwin.so
Architectures in the fat file: _imaging.cpython-38-darwin.so are: x86_64 arm64
You will get Pillow to work with libjpeg. You can do the same setup for OPENJPEG LIBTIFF etc.
--------------------------------------------------------------------
PIL SETUP SUMMARY
--------------------------------------------------------------------
version Pillow 8.1.0
platform darwin 3.8.2 (default, Nov 4 2020, 21:23:28)
[Clang 12.0.0 (clang-1200.0.32.28)]
--------------------------------------------------------------------
--- JPEG support available
*** OPENJPEG (JPEG2000) support not available
--- ZLIB (PNG/ZIP) support available
*** LIBIMAGEQUANT support not available
*** LIBTIFF support not available
*** FREETYPE2 support not available
*** LITTLECMS2 support not available
*** WEBP support not available
*** WEBPMUX support not available
*** XCB (X protocol) support not available
--------------------------------------------------------------------
Sorry to bring this back up.
But I'm trying to find any documentation on adding M1 Native to Travis CI. Any docs or hints you could share? I'm trying to help out pymupdf, but I'm kind of guessing in the dark here since I've never touched Travis CI.
Nothing yet but https://docs.travis-ci.com/user/reference/osx/ is probably the place to look.
In general, GitHub Actions adopts new things more quickly.
In case this is helpful to anyone, here's a wheel I put together on my M1 - Pillow-8.0.1-cp39-cp39-macosx_11_0_arm64.whl.zip
Thank you !!! a lot !
I've created https://github.com/python-pillow/pillow-wheels/pull/185 to add arm64 wheels to pillow-wheels. Unfortunately, it first requires macOS 11 pools - see https://github.com/actions/virtual-environments/issues/2486
For some reason I can't pip install Pillow
if I don't have ffmpeg installed
Platform: M1 MacBook runs macOS 11.2
Python: version 3.9.1
Pip: version 21.0.1
@alimehasin It could be the libxcb dependency issue. Try to use flag --disable-xcb, or install libxcb using brew (with “arch -arm64” if native).
For some reason I can't
pip install Pillow
if I don't have ffmpeg installed Platform: M1 MacBook runs macOS 11.2 Python: version 3.9.1 Pip: version 21.0.1
Thank you!
This solved my issue, brew install ffmpeg
fixed the default install process for me.
if I try to sudo python3 -m pip install --upgrade Pillow
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "
The headers or library files could not be found for jpeg, a required dependency when compiling Pillow from source.
@jurihahn Did you try without sudo
?
Please provide the output of this command:
uname -a ; brew --version ; python3 --version ; python3 -m pip --version
What did you do?
I tried installing a pillow with the pipenv, I have a python version 3.9.1 installed and tried to install a pillow with that but facing this issue mentioned below.
What did you expect to happen?
I wanted to use pillow with django.
What actually happened?
Pillow installation causing error continuously, the error is mentioned below.
What are your OS, Python, and Pillow versions?