我正在尝试使用Python 2.6.1,GCC 4.2.1,PIL 1.1.7在Snow Leopard上安装PIL,并尝试使用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
除了selfima.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
请帮忙!这太荒谬了.我甚至很高兴能够在这一点上编译PIL sans jpeg支持!
解决方法:
我最近写了一篇关于如何让PIL,django,libjpeg与Snow Leopard一起工作的文章
http://appelfreelance.com/2010/06/libjpeg-pil-snow-leopard-python2-6-_jpeg_resync_to_restart/
我也会在这里为你复制它.
如果您没有先下载它.
07001
通过运行以下命令进入shell环境并解压缩
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并解压缩它
07002
tar -zxvf Imaging-1.1.6.tar.gz
cd Imaging-1.1.6
如果你已经有PIL我会建议你跑
sudo rm -Rf build
清理任何现有的构建,这已经导致我的错误和白发!
在您的settings.py文件中运行find 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”)
应该没有错误地工作