5

When trying to import PIL (using Pillow), I get the following error:

    from PIL import ImageTk, Image
  File "/usr/local/lib/python2.7/site-packages/PIL/ImageTk.py", line 42, in <module>
    from . import Image
  File "/usr/local/lib/python2.7/site-packages/PIL/Image.py", line 60, in <module>
    from . import _imaging as core
ImportError: dlopen(/usr/local/lib/python2.7/site-packages/PIL/_imaging.so, 2): Symbol not found: _clock_gettime
  Referenced from: /usr/local/lib/python2.7/site-packages/PIL/.dylibs/liblzma.5.dylib (which was built for Mac OS X 10.12)
  Expected in: /usr/lib/libSystem.B.dylib
 in /usr/local/lib/python2.7/site-packages/PIL/.dylibs/liblzma.5.dylib

Note the line Referenced from: /usr/local/lib/python2.7/site-packages/PIL/.dylibs/liblzma.5.dylib (which was built for Mac OS X 10.12) and specifically '(which was built for Mac OS X 10.12)'.

I have a hunch that I may have corrupted something when I attempted to manually install the wrong version of xCode (not compatible with 10.11.6, which is on this computer). I have installed Pillow using pip install Pillow - but that installation resulted in this error. Is there a way to force pip to install a certain version of Pillow, to see if the problem lies in pip installing a problematic version?

user3.1415927
  • 367
  • 3
  • 19

2 Answers2

5

This is a bug in the latest Pillow 5.1.0 release.

It was caused by upgrading Xcode from version 8 to 9.2 for building the binary wheels.

El Capitan 10.11 is the "min macOS to run" for Xcode 8.

Sierra 10.12.6 is the min for Xcode 9.2.

https://en.wikipedia.org/wiki/Xcode#Xcode_7.0_-9.x(since_Free_On-Device_Development

There will be a Pillow 5.1.1 out to fix it at some point.

In the meantime, the workaround is: pip install 'pillow!=5.1.0'

(Or upgrade your macOS, or build from source.)

For more info, see https://github.com/python-pillow/Pillow/issues/3068

Hugo
  • 27,885
  • 8
  • 82
  • 98
  • 1
    Thank you for the workaround, this sounds exactly like the symptoms of my issue. I’ll try it ASAP. – user3.1415927 Apr 23 '18 at 18:52
  • In 2023, matplotlib 3.6.2 -> PIL 9.4.0 on macos 10.14.6 gives a similar dlopen error. https://github.com/python-pillow/Pillow/issues/6179 has a nice table that says "macos 10.14 is not supported, upgrade to 10.15"; sigh, versionitis ... – denis Jan 02 '23 at 11:33
0

That sounds like the wheel uploaded to PyPI was not built for your platform correctly. Unfortunately having the wheel for a PyPI package for your platform is not a guarantee that the wheel will install or work correctly, you're at the mercy of the PyPI package maintainer in this regard.

You should run pip uninstall Pillow, download the source directly from PyPI, build it manually and run pip install -e <path to rebuilt package> to install the wheel you built specifically for your machine.

JacaByte
  • 325
  • 2
  • 8
  • Do you mean to download, build and install the `wheel` module (wrong word?) that I see when I do `pip list`? Or to download, build and install the Pillow wheel? ... because I found the Pillow wheel [here](https://pypi.org/project/Pillow/#files), but haven't found how to build and reinstall `wheel` (which is currently showing as v 0.31.0). – user3.1415927 Apr 23 '18 at 16:41
  • Also, should I be using the .whl file, or should I use the `source` file? I realize this might sound like a stupid question, but I'm brand new to working with python and this wheel notion... – user3.1415927 Apr 23 '18 at 16:44
  • The source is the .tar.gz file listed among these files; https://pypi.org/project/Pillow/#files A wheel is a file with binary libraries used by pip to install a package without requiring a build. This allows users to install packages on computers that don't have a compiler. – JacaByte Apr 24 '18 at 02:21