我不知道为什么,但即使是最简单的脚本,python也会崩溃,我得到以下消息:
“activepython 3.4意外退出。”
我在一个Mac, OSX 10.7.5上运行它。
我要测试的代码是:

from tkinter import *
from PIL import Image, ImageTk

root = Tk()

image = Image.open("/Users/Name/Desktop/image.png")
photo = ImageTk.PhotoImage(image)
image_label = Label(root, width = 400, height = 400, image = photo)

root.mainloop()

我认为这是Tkinter而不是PIL的问题,因为以下代码工作正常:
from PIL import Image, ImageTk

image = Image.open("/Users/Name/Desktop/image.png")
image.show()

你猜这是为什么吗?
我想我应该发布一段错误日志,不管它有多长,希望它能以某种方式帮助解决这个令人沮丧的问题。
Process:         Python [377]
Path:            /Library/Frameworks/Python.framework/Versions/3.4/Resources/Python.app/Contents/MacOS/Python
Identifier:      org.python.python
Version:         3.4.1 (3.4.1)
Code Type:       X86-64 (Native)
Parent Process:  Python [286]

Date/Time:       2015-05-26 19:43:38.689 +1000
OS Version:      Mac OS X 10.7.5 (11G63)
Report Version:  9

Interval Since Last Report:          17865335 sec
Crashes Since Last Report:           138
Per-App Interval Since Last Report:  152 sec
Per-App Crashes Since Last Report:   18
Anonymous UUID:                      7F4893CF-A95E-4ED6-85E7-2B6A5A32AC0C

Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000050

VM Regions Near 0x50:
-->
    __TEXT                 0000000100000000-0000000100001000 [    4K] r-x/rwx SM=COW  /Library/Frameworks/Python.framework/Versions/3.4/Resources/Python.app/Contents/MacOS/Python

Application Specific Information:
objc[377]: garbage collection is OFF

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   Tk                              0x0000000105332fb6 Tk_GetImageMasterData + 18
1   Tk                              0x0000000105340fbf Tk_FindPhoto + 17
2   _imagingtk.so                   0x000000010305caec PyImagingPhotoPut + 92
3   Tcl                             0x00000001051df261 TclInvokeStringCommand + 121
4   Tcl                             0x00000001010714b1 TclEvalObjvInternal + 782
5   Tcl                             0x00000001010726a3 Tcl_EvalObjv + 66
6   _tkinter.so                     0x00000001007f1ace Tkapp_Call + 190
7   org.python.python               0x00000001000e542b PyEval_EvalFrameEx + 31291
8   org.python.python               0x00000001000e665d PyEval_EvalCodeEx + 2349
9   org.python.python               0x00000001000e51f7 PyEval_EvalFrameEx + 30727
10  org.python.python               0x00000001000e665d PyEval_EvalCodeEx + 2349
11  org.python.python               0x000000010003f76a function_call + 186
12  **org.python.python                 0x000000010000da08 PyObject_Call + 104
13  org.python.python               0x000000010002941c method_call + 140
14  org.python.python               0x000000010000da08 PyObject_Call + 104
15  org.python.python               0x0000000100078651 slot_tp_init + 81
16  org.python.python               0x00000001000736c4 type_call + 212
17  org.python.python               0x000000010000da08 PyObject_Call + 104
18  org.python.python               0x00000001000e1c3f PyEval_EvalFrameEx + 16975
19  org.python.python               0x00000001000e665d PyEval_EvalCodeEx + 2349
20  org.python.python               0x00000001000e671f PyEval_EvalCode + 63
21  org.python.python               0x00000001000dae3e builtin_exec + 206
22  org.python.python               0x00000001000e542b PyEval_EvalFrameEx + 31291
23  org.python.python               0x00000001000e665d PyEval_EvalCodeEx + 2349
24  org.python.python               0x000000010003f76a function_call + 186
25  org.python.python               0x000000010000da08 PyObject_Call + 104
26  org.python.python               0x00000001000e0ffe PyEval_EvalFrameEx + 13838
27  org.python.python               0x00000001000e665d PyEval_EvalCodeEx + 2349
28  org.python.python               0x00000001000e51f7 PyEval_EvalFrameEx + 30727
29  org.python.python               0x00000001000e665d PyEval_EvalCodeEx + 2349
30  org.python.python               0x00000001000e671f PyEval_EvalCode + 63
31  org.python.python               0x00000001001111e7 PyRun_StringFlags + 183
32  org.python.python               0x0000000100111271 PyRun_SimpleStringFlags + 65
33  org.python.python               0x0000000100127e55 Py_Main + 1445
34  org.python.python               0x0000000100000e32 0x100000000 + 3634
35  org.python.python               0x0000000100000c84 0x100000000 + 3204**

最佳答案

我在github上发布了我的问题,用户“radarhere”向我指出了解决方案。
Tk扩展库有时会链接到/System/Library/Frameworks而不是/Library/Frameworks可能有一种更优雅的方法可以做到这一点,但我只是简单地重命名了路径system/library/frameworks和voila中的tcl.frameworks和tk.frameworks文件夹!没有python崩溃,图像按预期显示。

10-07 12:35