There are some similar questions here and especially here, but they don't go into quite the detail I'm seeking.
I'm attempting to read and edit JP2 (aka, JPEG2000) files using pillow. My code is below, and I suppose I don't yet have the OpenJPEG library installed, because I get the error module 'PIL._imaging' has no attribute 'jpeg2k_decoder'. So, I believe that I neeed to install OpenJPEG. Because I it's a system install (not contained within a virtual environment) and the instructions are piecemeal, I'm hoping to get more info.
Pillow's documentation indicates:
To enable JPEG 2000 support, you need to build and install the OpenJPEG library, version 2.0.0 or higher, before building the Python Imaging Library.
And OpenJPEG's install instructions aren't very clear, but seems to also require installation of cmake. The general advice I see everywhere is to uninstall pillow, install the OpenJPEG library, and then reinstall pillow. And I see that people often have to troubleshoot because pillow's reinstall doesn't pick up the new library sometimes.
I'm hoping that those who have been through the process on a Mac can advise on some details:
- cmake appears to be required for installing OpenJPEG. Are the instructions at https://cmake.org/install/ sufficient?
- The OpenJPEG instructions don't seem complete. Has anyone made step by step instructions that are easier to follow?
Code that returns the error:
from PIL import Image
import urllib.request
from io import BytesIO
url = 'https://chroniclingamerica.loc.gov/data/batches/dlc_golf_ver01/data/sn84025891/100493731/1901082401/0132.jp2'
img_raw = requests.get(url)
img = Image.open(BytesIO(img_raw.content))
display(img)
------ Outputs an error including: -------
AttributeError: module 'PIL._imaging' has no attribute 'jpeg2k_decoder'
Thanks!
IMHO, the easiest way to manage packages under macOS, such as OpenJPEG, is with homebrew.
All you need is:
Search for available packages containing "jp" with:
Sample Output
Get info about a package with:
Sample Output
Check what files are in a package with:
Sample Output
Check how PIL is configured with:
Sample Output