1

After installing Pillow, I get errors such as:

>>> from PIL import Image
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/env/lib/python3.7/site-packages/PIL/Image.py", line 90, in <module>
    from . import _imaging as core
ImportError: libopenjp2.so.7: cannot open shared object file: No such file or directory

I could, one by one, find all these additional libraries required and install them individually, but it would much more convenient to have a canonical list or a single package that took care of them.

I though the python-pil system package would install all these, and it does, as well as Pillow itself, but Pillow installed via Pip - for example in a virtualenv, which I need - will not find the libraries that python3-pil includes.

Is there a more convenient way of installing these libraries?

5
  • Does pillow.readthedocs.io/en/stable/… help?
    – Dirk
    Oct 14, 2019 at 15:14
  • It sounds like you have installed software without using the package system (package system modules are tested for compatability).
    – joan
    Oct 14, 2019 at 15:24
  • The Pillow docs are useful and give some examples in the /depends section of the repository for system-level dependencies that will be required on various systems, but the closest match was (I think) Debian 8. Oct 14, 2019 at 16:36
  • I think it's critical to reframe this question as being inside a virtual environment. Otherwise, sudo apt install python3-pil will do the needful for most users.
    – scruss
    Oct 15, 2019 at 14:24
  • @scruss I don't think it is the virtual environment that makes the difference, but the installation of Pillow with Pip. However I would need to check. Oct 15, 2019 at 18:59

2 Answers 2

3

Did you install python3-pil? python-pil is for Python 2, which you aren't running.

It looks like the problem is more you're trying to open a JPEG-2000 image (… ImportError: libopenjp2.so.7: cannot open shared object file …). For reasons of mostly-obsolete dogma, JP2 support on Linux has been weak for many years. You may find that installing libopenjp2 fixes the problem:

sudo apt install libopenjp2-7 libopenjp2-7-dev libopenjp2-tools
2
  • docs suggest Pillow uses openjpeg, but your system was explicitly looking for libopenjp2
    – scruss
    Oct 14, 2019 at 15:49
  • Well-spotted regarding python3-pil, I missed that. However, having installed it, I still have the same result. I'm not trying yet to open any particular image - just from PIL import Image, in the example above, which appears to demand libopenjp2.so.7. From experience, once that's fixed, the next complaint will be about a TIFF library, and so on. Oct 14, 2019 at 16:39
3

I found the answer I was looking for.

In short, it's:

sudo apt install libwebp6 libtiff5 libjbig0 liblcms2-2 libwebpmux3 libopenjp2-7 libzstd1 libwebpdemux2

I found the list at https://www.piwheels.org/project/Pillow/.

Once I have those installed, Pillow seems to work as expected in my virtual environment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.