OSX Pillow 不兼容的库版本 libtiff.5.dylib 和 libjpeg.8.dylib

8 投票
6 回答
17554 浏览
提问于 2025-04-18 00:24

我在使用Pillow这个库的时候,遇到了这个错误,任何脚本都不行:

  File "/Users/antonio/WWW/myproj/myproj/functions.py", line 12, in <module>
    from PIL import Image, ImageOps
  File "/Library/Python/2.7/site-packages/PIL/Image.py", line 53, in <module>
    from PIL import _imaging as core
ImportError: dlopen(/Library/Python/2.7/site-packages/PIL/_imaging.so, 2): Library not loaded: /usr/local/lib/libjpeg.8.dylib
  Referenced from: /usr/local/lib/libtiff.5.dylib
  Reason: Incompatible library version: libtiff.5.dylib requires version 13.0.0 or later, but libjpeg.8.dylib provides version 9.0.0

有没有人能帮我一下?

6 个回答

1

我也遇到过同样的问题。因为我是通过Anaconda安装的Python,所以在这种情况下,使用“conda install Pillow”这个命令是有效的。

3

如果你在用conda的话,可以试试:

conda install libtiff

如果你不是用conda,那就试试:

pip install --upgrade libtiff
4

我在OSX 10.10.2上遇到了一个非常相似的问题。我也在用anaconda来运行python,版本是Python 2.7.9 |Anaconda 2.2.0 (x86_64)。Frank和user4183543的回答都是不错的尝试,但对我来说并没有用

我创建了指向未加载库的软链接,这个方法对我有效。

我执行了:

$ locate libtiff.5.dylib

结果中有

/Users/curt/anaconda/lib/libtiff.5.dylib
/Users/curt/anaconda/pkgs/libtiff-4.0.2-1/lib/libtiff.5.dylib

对于libjpeg.8.dylib的结果也是类似的。我通过以下命令为libjpeg.8.dyliblibtiff.5.dylib创建了软链接:

$ ln -s /Users/curt/anaconda/lib/libjpeg.8.dylib /usr/local/lib/libjpeg.8.dylib
$ ln -s /Users/curt/anaconda/lib/libtiff.5.dylib /usr/local/lib/libtiff.5.dylib

Pillow / PIL现在对我来说可以正常工作,至少目前是这样。

我相信还有更好的解决方案可以找到核心问题,但我发这个帖子是为了帮助那些可能遇到类似问题的conda用户。

5

试着重新安装最新版本的pillow库。我用的是anaconda的python,

conda install -f pillow

这样解决了我遇到的类似问题。

6

我之前也遇到过同样的问题,所以我重新安装了pillow和它所有的依赖项。我的一些符号链接(symlink)设置得不太对。

首先,你需要做的是:

brew doctor

然后看看有没有错误。我遇到的错误是这样的:

Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected dylibs:
/usr/local/lib/libjpeg.8.dylib
/usr/local/lib/libpng.3.dylib
/usr/local/lib/libpng12.0.dylib
/usr/local/lib/libpng14.14.dylib

Warning: Unbrewed .la files were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected .la files:
/usr/local/lib/libjpeg.la
/usr/local/lib/libpng12.la
/usr/local/lib/libpng14.la
/usr/local/lib/libpng15.la

Warning: Unbrewed .pc files were found in /usr/local/lib/pkgconfig.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

 Unexpected .pc files:
/usr/local/lib/pkgconfig/libpng12.pc
/usr/local/lib/pkgconfig/libpng14.pc

Warning: Unbrewed static libraries were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected static libraries:
/usr/local/lib/libjpeg.a
/usr/local/lib/libpng12.a
/usr/local/lib/libpng14.a

所以我决定清理掉所有的错误和我安装的依赖项:

brew uninstall pillow
brew uninstall libpng
brew uninstall libjpeg
brew uninstall webp
brew uninstall libtiff
brew uninstall littlecms

brew prune => to clean symlink

当我的brew doctor没有任何错误时,我就运行了 brew install pillow,一切都正常了。

希望这能帮到你。

撰写回答