Python 3.4 crash when opening image with PIL in tkinter

I have no idea why, but even for the simplest scenarios, Python crashes and I get the following message:

"ActivePython 3.4 exited unexpectedly."

I am using it on Mac, OSX 10.7.5

.

The code I'm running to test this:

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()

      

I think this is a Tkinter issue, not PIL, because the following code works fine:

from PIL import Image, ImageTk 

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

      

Any suggestions why this might be?

I thought I would post the error log section no matter how long it takes, in the hopes that it would somehow help fix this nasty issue.

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**

      

+4


source to share


1 answer


I submitted my question to github and the custom "radar" pointed me to a solution.



Tk extension libraries are sometimes referred to as / System / Library / Frameworks instead of / Library / Frameworks. This is probably a more elegant way to do it, but I just renamed the Tcl.frameworks and TK.frameworks folders in the System / Library / Frameworks path and voila! There is no python crash and the image is displayed as expected.

0


source







All Articles