在Snow Leopard上安装PIL -- 什么都无法工作

3 投票
3 回答
2799 浏览
提问于 2025-04-16 01:08

我在尝试在Snow Leopard上安装PIL,使用的是Python 2.6.1、GCC 4.2.1和PIL 1.1.7。我试过libjpeg6b和libjpeg7,但都没成功。我已经把fink里所有libjpeg、pil和zlib的痕迹都清理掉了,尝试了各种编译选项,还用过http://jetfar.com/libjpeg-and-python-imaging-pil-on-snow-leopard/和http://www.brambraakman.com/blog/comments/installing_pil_in_snow_leopard_jpeg_resync_to_restart_error/(这不是链接,因为StOv只让我发一个……)

这里有4条可能有用的信息:

OTOOL没有把libjpeg显示为依赖项

otool -L /Library/Python/2.6/site-packages/PIL/_imaging.so
/Library/Python/2.6/site-packages/PIL/_imaging.so:
 /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)

我收到了这些奇怪的编译器消息

i686-apple-darwin10-gcc-4.2.1: -framework: linker input file unused because linking not done
i686-apple-darwin10-gcc-4.2.1: Tcl: linker input file unused because linking not done
i686-apple-darwin10-gcc-4.2.1: -framework: linker input file unused because linking not done
i686-apple-darwin10-gcc-4.2.1: Tk: linker input file unused because linking not done
gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch ppc -arch x86_64 -pipe -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/sw/include/freetype2 -I/sw/include -I/opt/local/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include -I/usr/local/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c Tk/tkImaging.c -o build/temp.macosx-10.6-universal-2.6/Tk/tkImaging.o -framework Tcl -framework Tk
In file included from /System/Library/Frameworks/Tk.framework/Headers/tk.h:78,
                 from Tk/tkImaging.c:51:

selftest.py因为_imagingmath失败(在我使用了上面给的第二个链接之后,之前也因为_imaging失败过)

Themistocles:Imaging-1.1.7 me$ python selftest.py 
Traceback (most recent call last):
  File "selftest.py", line 11, in <module>
    from PIL import ImageMath
  File "./PIL/ImageMath.py", line 19, in <module>
    import _imagingmath
ImportError: No module named _imagingmath

除了selftest.py,其他的都因为_imaging失败

>>> import _imaging
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(/Library/Python/2.6/site-packages/PIL/_imaging.so, 2): Symbol not found: _jpeg_resync_to_restart
  Referenced from: /Library/Python/2.6/site-packages/PIL/_imaging.so
  Expected in: flat namespace
 in /Library/Python/2.6/site-packages/PIL/_imaging.so

求求你们,帮帮我!这真是太荒谬了。现在我甚至愿意能编译没有jpeg支持的PIL!

3 个回答

0

我在尝试安装PIL的时候,总是会遇到很多gcc错误,屏幕上显示的信息多得像好几页一样。后来我找到了一个办法(可能是通过MacPorts),现在我的解决方案是把它复制到合适的site-packages文件夹里(比如放在一个新的虚拟环境里面)。

我刚刚把这个解决方案发布在这里:http://blogmaker.com/PIL-1.1.6-for-MacOSX-10.5-Leopard.zip

对我来说是有效的,但我不知道对其他人是否也有效!如果你有建议,欢迎联系我。另外,如果有更合适的地方可以发布这个信息,请告诉我。PIL既很酷又很麻烦,能有一个明确的支持地方就太好了。我还有其他与PIL相关的问题一直没解决。

1

下载 macport:

http://www.macports.org/install.php

然后用它来安装 pil:

http://trac.macports.org/browser/trunk/dports/python/py-pil/Portfile

我也遇到过很多麻烦,不过最终还是用 port 解决了。

5

我最近写了一篇文章,讲的是如何让PIL、django和libjpeg在Snow Leopard上顺利工作。

http://appelfreelance.com/2010/06/libjpeg-pil-snow-leopard-python2-6-_jpeg_resync_to_restart/

我也把内容复制在这里给你。

如果你还没有这个,先下载它。

http://www.ijg.org/files/jpegsrc.v7.tar.gz

打开你的命令行工具,解压文件,运行以下命令:

tar -zxvf jpegsrc.v7.tar.gz
cd jpeg-7

然后运行:

sudo make clean
sudo CC="gcc -arch i386”"./configure --enable-shared --enable-static
sudo make
sudo make install

接下来,下载PIL并解压:

http://effbot.org/downloads/Imaging-1.1.6.tar.gz
tar -zxvf Imaging-1.1.6.tar.gz
cd Imaging-1.1.6

如果你已经安装了PIL,建议你先运行:

sudo rm -Rf build

这样可以清理掉之前的构建,这样可以避免很多错误,让我头疼不已!

在你的settings.py文件中,找到JPEG_ROOT。

把它改成这样:

JPEG_ROOT = libinclude(“/usr/local”)

接下来进行构建:

sudo python setup.py build

如果libjpeg安装成功,你应该能运行python selftest.py,而不会出现与“jpeg”相关的错误。

sudo python setup.py install

如果一切顺利,你可以在命令行中输入python,进入Python解释器,并且可以执行以下命令:

import PIL
import Image
import _imaging

而不会出现任何错误。

为了再确认一下,我在桌面上放了一张简单的jpeg图片。

image = Image.open(“/Users/MyName/Desktop/myimage.jpeg”)
image.save(“/Users/MyName/Desktop/test.jpeg”)

应该可以顺利执行,没有错误。

撰写回答