【问题标题】:Installing PIL on Snow Leopard -- NOTHING WORKS在 Snow Leopard 上安装 PIL -- 没有任何作用
【发布时间】:2011-03-14 13:40:11
【问题描述】:

我正在尝试在 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/cmets/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

请,请帮助!这越来越荒谬了。我什至很高兴现在能够编译 PIL sans jpeg 支持!

【问题讨论】:

    标签: python gcc osx-snow-leopard python-imaging-library libjpeg


    【解决方案1】:

    我最近写了一篇关于如何让 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

    进入你的shell环境并通过运行以下命令解压

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

    然后运行

    sudo 使清洁
    sudo CC="gcc -arch i386""./configure --enable-shared --enable-static
    须藤制作
    须藤制作安装

    接下来获取 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 构建

    要清理任何现有的构建,这给我带来了很多错误和白发!

    在你的 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 解释器,并执行以下操作:

    导入 PIL
    导入图片
    导入_成像

    没有任何错误。

    为了三重检查,我的桌面上有一个简单的 jpeg。

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

    应该可以正常工作

    【讨论】:

    • +11111!!!按照上面的说明(注意首先清除预先存在的 libjpeg 安装)是我在多次失败后最终成功的解决方案。对于其他人,我在运行 selftest.py 时也得到了ImportError: No module named _imagingmath,但这似乎并不重要,因为最后我可以import _imaging 没有_jpeg_resync_to_restart 错误
    • 啊,不!我仍然得到IOError: decoder jpeg not available ...扯掉我的头发!
    • 啊,是的!我忘了在 libjpeg 上执行 sudo make install 命令,从头开始,它现在真的有效。理智恢复了!
    • 现在它抱怨libz。我通过在 setup.py 禁用 libs.append(feature.zlib)defs.append(("HAVE_LIBZ", None)) 行来解决问题。好伤心。
    【解决方案2】:

    下载macport:

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

    然后将其用于pil:

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

    我也遇到了很多麻烦,但端口管理。

    【讨论】:

    • 我应该删除已安装的 libjpeg/PIL 的副本吗?
    • 等一下,macports 是想安装自己的 Python,还是和系统兼容?
    • 我在运行它时已经安装了一个更新的 python,所以我不完全确定。它可能想重新安装 fink 已经拥有的一堆东西,我从未将两者结合使用。
    • @Harkonnen:MacPorts 会想要安装它自己的 python - Python 2.4!如果您想让它与系统的 Python 一起工作,您可以尝试手动将其复制到 Python 的 site-packages 目录(不确定这是否适用于您的情况),或者您可能只是在 Portfile 中查看看看他们是否制作了任何补丁来构建它。它还应该让您了解要拍摄的 libjpeg 版本。
    • Macports 坚持安装自己的 Python,我真的不想要……有没有办法解决这个问题?
    【解决方案3】:

    在尝试安装 PIL 时,我总是遇到几个 gcc 错误。在某些时候我得到了一些工作(可能通过 MacPorts),所以现在我的解决方案是将它复制到适当的站点包(例如在新的 virtualenv 中)。

    我刚刚发布在这里:http://blogmaker.com/PIL-1.1.6-for-MacOSX-10.5-Leopard.zip

    为我工作;我不知道它是否适用于其他人!如有建议,请随时与我联系。并且,让我知道是否有更好的地方我应该发布它。 PIL 既酷又麻烦。有一个明确的支持位置会很好。还有其他与 PIL 相关的问题我从未解决。

    【讨论】:

    • 通过搜索找到这篇文章的人的更新:还有一个名为 Pillow 的 PIL 分支,旨在更容易安装。见pypi.python.org/pypi/Pillow(我没测试过,下次一定要安装)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-02
    • 2023-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多