【问题标题】:python ImageTk.PhotoImage - segfaultpython ImageTk.PhotoImage - 段错误
【发布时间】:2012-02-26 21:43:36
【问题描述】:

我正在尝试在 Mac 10.6.8 上运行以下命令:

Python 2.7.2 |EPD 7.1-2 (64-bit)| (default, Jul 27 2011, 14:50:45) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin

import Image 
import ImageTk
from Tkinter import Tk

window = Tk()
i = Image.open("file.jpg")
photo = ImageTk.PhotoImage(i)
Segmentation fault

我看到其他人在这种情况下遇到了总线错误。有谁知道这里的错误或解决方法?我不明白http://infohost.nmt.edu/tcc/help/pubs/pil/image-tk.html 是否相关。谢谢!

很抱歉,即使在升级 EPD 之后也会发生同样的事情:

Python 2.7.2 |EPD 7.2-2 (64-bit)| (default, Sep  7 2011, 16:31:15) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin

【问题讨论】:

  • Segmentation fault什么时候出现?尝试保存对图像的引用,例如window.image = photo
  • 它并没有那么远 - segfault 紧跟在 photo = ImageTk.PhotoImage(i) 之后,所以我不能尝试 window.image = photo。
  • window.image=ImageTk.PhotoImage(i) 也会导致段错误。
  • 在另一台运行 Lion 10.7.2 的机器上,错误是 Segmentation fault: 11

标签: python segmentation-fault tkinter


【解决方案1】:

现在固定在

Enthought Canopy Python 2.7.6 | 64-bit | (default, Apr 11 2014, 11:55:30) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

【讨论】:

    【解决方案2】:

    如果您没有使用 Apple 的 Tcl/Tk,请尝试在 _imagingtk.so 上运行 otool -L 以查看它是否在 /System/Library 中查找其共享库。它应该查看/Library,而不是/System/Library。如果是这样,您可以使用install_name_tool 更改库搜索路径。

    【讨论】:

    • 我如何知道我是否在使用 Apple 的 Tcl/Tk?如果我使用的是标准 Anaconda 安装,是否足以判断我是否使用 Apple 的 Tcl/Tk?
    【解决方案3】:

    您是否尝试过在 32 位模式下运行 Mac Python?

    查看胖二进制文件:

    cd /usr/bin/
    file python
    

    我明白了:

    python: Mach-O universal binary with 2 architectures
    python (for architecture x86_64):   Mach-O 64-bit executable x86_64
    python (for architecture i386): Mach-O executable i386
    

    要尝试 32 位模式,您可以这样做:

    arch -i386 /usr/bin/python
    

    如果可行,那么它至少是一种解决方法。

    【讨论】:

    • 不幸的是,这将需要安装大量依赖项才能在 32 位下运行。我开始安装一些,但因为它在我的系统上呈指数级增长而放弃了。
    • 谢谢卡尔 - 完全正确。我已经通过电子邮件发送了 EDP 用户列表,正在等待他们的回复。可惜没有人为赏金而去(非常感谢!)。
    猜你喜欢
    • 1970-01-01
    • 2011-09-03
    • 2016-01-31
    • 1970-01-01
    • 2013-10-08
    • 1970-01-01
    • 1970-01-01
    • 2015-04-12
    • 2021-08-15
    相关资源
    最近更新 更多