从Pillow导入ImageCms时出现'_util'模块缺失错误求助
Fixing ImportError/ModuleNotFoundError When Importing ImageCms from Pillow 6.0.0
Looks like you're hitting two linked issues with Pillow 6.0.0's ImageCms module—let's break down how to fix this:
Solution 1: Upgrade Pillow (Recommended)
The easiest and most reliable fix is to upgrade to a newer version of Pillow, where both the _imagingcms dependency handling and the _util import path bug have been resolved. Run this command in your terminal:
pip install --upgrade pillow
After upgrading, try importing ImageCms again—it should work without errors.
Solution 2: Reinstall Pillow with LCMS2 Support (If You Can't Upgrade)
If you absolutely need to stick with Pillow 6.0.0, the root issue is likely that Pillow wasn't compiled with LCMS2 (the color management library ImageCms relies on) support. Here's how to fix that:
- First, install the system-level LCMS2 development library:
- On Ubuntu/Debian-based systems:
sudo apt-get install liblcms2-dev - On macOS (using Homebrew):
brew install lcms2
- On Ubuntu/Debian-based systems:
- Then force a reinstall of Pillow to ensure it compiles with LCMS2 support:
pip install --force-reinstall pillow==6.0.0 - Additionally, you'll need to fix the broken import path in
ImageCms.py:
Locate the file at~/anaconda3/lib/python3.6/site-packages/PIL/ImageCms.py, find line 27 where it says:
Change it to:from _util import deferred_error
This fixes thefrom PIL._util import deferred_errorModuleNotFoundError: No module named '_util'issue.
Why This Happens
- The first error (
ImportError: cannot import name '_imagingcms') occurs because Pillow 6.0.0 requires the LCMS2 library to build the_imagingcmsextension module. If LCMS2 wasn't present during installation, this module isn't compiled, causing the import failure. - The second error (
ModuleNotFoundError: No module named '_util') is a bug in Pillow 6.0.0'sImageCms.py—it tries to import_utildirectly instead of referencing it asPIL._util, which is the correct package path.
内容的提问来源于stack exchange,提问作者G M
相关产品推荐
相关产品推荐

