在 Mac OS X Mavericks (10.9.1) 上安装 Pillow

6

我正在按照指示安装Pillow:

http://pillow.readthedocs.org/en/latest/installation.html#mac-os-x-installation

问题在于,我在运行python -c 'from PIL import Image时出现了错误。

 python -c "from PIL import Image"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  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): 
             Symbol not found: _jpeg_resync_to_restart
  Referenced from: /Library/Python/2.7/site-packages/PIL/_imaging.so
  Expected in: flat namespace
 in /Library/Python/2.7/site-packages/PIL/_imaging.so

该信息显示找不到“_jpeg_resync_to_restart”,我通过谷歌搜索尝试解决该问题,如下所示:
  1. 使用brew安装Pillowhttps://github.com/Homebrew/homebrew-python
  2. 安装libjpeg并从源代码安装:http://www.thetoryparty.com/2010/08/31/pil-on-snow-leopard-_jpeg_resync_to_restart-error/
然而,这些方法都没有奏效。有没有办法在Mavericks上安装Pillow?我使用的是Python 2.7:默认的python解释器。
6个回答

7
我确认按照以下步骤,我可以在Mavericks 10.9.2和XCode 5上安装Pillow。
1:
brew install libtiff libjpeg webp littlecms

2: 前往此处https://pypi.python.org/pypi/Pillow/2.3.1下载zip文件并解压缩它。

3: 打开终端窗口,进入终端中的Pillow-2.3.1文件夹。

4: 这两行非常重要,因为它们将在安装Pillow时忽略错误,如果没有这两行,则无法完成设置 (我正在使用Python 2.7,因此您可能需要更改您使用的版本):

sudo sed -i '' -e 's/-mno-fused-madd//g' /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_sysconfigdata.py
sudo rm /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_sysconfigdata.pyc

5:运行命令

sudo python setup.py install

完成!


你在编译后有检查过 Pillow 的 Tests 目录中所有测试是否都通过了吗? - prosseek
我还没有检查Tests目录。但在安装之前,我遇到了错误。安装后,我运行了这个命令 python -c "from PIL import Image" 没有显示任何错误。 - newguy
顺便提一下,我正在引用问题链接 - newguy

6

请按照以下步骤操作:

  1. 在qppstore上更新xcode
  2. 打开终端并输入以下命令:
    1. xcode-select --install
    2. su
    3. export CFLAGS=-Qunused-arguments
    4. export CPPFLAGS=-Qunused-arguments
    5. pip install pillow

5
可以说明每一步的作用及其必要性吗? - Jason Aller

3

一个朋友告诉我如何解决这个问题:

  1. sudo su -
  2. export CFLAGS=-Qunused-arguments
  3. pip install Image
  4. python
  5. from PIL import Image

作者:https://github.com/moskytw


2
请注意,这将全局安装Django。 - Blaise

1

我在2015年11月遇到了这个问题。对我来说最简单的解决方法是使用wheels安装pillow的预编译二进制文件:

pip install wheel
pip install --use-wheel pillow

0
  1. 从XQuartz.org重新安装X11
  2. 安装最新的XCode
  3. 安装命令行工具:

    xcode-select --install

在Mavericks上对我有用


2
请不要发布重复答案,这只会增加冗余。你的回答已经是一个完全重复的副本。 - Paresh Mayani

0

安装早期版本的Pillow对我有用

pip uninstall pillow
pip install Pillow==2.5.0

炸了,耶宝贝!

运行于MacOSX 10.8.5的from PIL import Image现在不会出错了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接