Segfault in Image.PhotoImage on OS X
This was reported here in February, but no debugging information was provided by the reporter: http://stackoverflow.com/questions/9142786/python-imagetk-photoimage-segfaul... <view-source:http://stackoverflow.com/questions/9142786/python-imagetk-photoimage-segfaul...> I can explain the nature of the problem, but I don't know how to fix it correctly. I am using the standard x86_64 Python 2.7.2 package from python.org and I have installed Active State Tcl/Tk 8.11. When I tried using easy_install to install PIL it would not load, claiming that _imaging.so did not exist. In fact, it existed but was only a thin i386 executable. So I compiled Imaging-1.1.7 with export CFLAGS='-arch i386 -arch x86_64' and export TCL_ROOT=/Library/Frameworks/Tcl.framework/Versions/8.5/Tcl I was then able to load the module. However, the following code produced a segfault: import Image import ImageTk import Tkinter W = Tkinter.Tk() Im = Image.open('test_image.jpg') x = ImageTk.PhotoImage(Im) The crash occurs in Tk_GetImageMasterData. More importantly, though, the crash was preceded by the following messages: objc[36554]: Class TKApplication is implemented in both /Library/Frameworks/Tk.framework/Versions/8.5/Tk and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined. objc[36554]: Class TKMenu is implemented in both /Library/Frameworks/Tk.framework/Versions/8.5/Tk and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined. objc[36554]: Class TKContentView is implemented in both /Library/Frameworks/Tk.framework/Versions/8.5/Tk and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined. objc[36554]: Class TKWindow is implemented in both /Library/Frameworks/Tk.framework/Versions/8.5/Tk and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined. Guessing that PIL was finding the System/Library/Frameworks/Tk.Framework instead of /Library/Frameworks/Tk.Framework, I tried hiding the system Tcl and Tk frameworks by renaming them. I was then able to create the PhotoImage and display it. I don't know where those messages come from, and I have never encountered them before. But I am guessing they are from OS X, since they are generated by an objective C program. Evidently _tkinter.so is able to specify which Tk.Framework to use. I don't know its mechanism for doing that. But, somehow, PIL is not doing it, and it ends up using the wrong one. A stack trace of the crash is below. - Marc 0x000000011517bccd in Tk_GetImageMasterData () (gdb) bt #0 0x000000011517bccd in Tk_GetImageMasterData () #1 0x0000000115183d9f in Tk_FindPhoto () #2 0x00000001014fbadc in PyImagingPhotoPut () #3 0x000000011502a05b in TclInvokeStringCommand () #4 0x000000010102142a in TclEvalObjvInternal () #5 0x000000010102261c in Tcl_EvalObjv () #6 0x000000010100646d in Tkapp_Call () #7 0x00000001000c102d in PyEval_EvalFrameEx () #8 0x00000001000c2d29 in PyEval_EvalCodeEx () #9 0x00000001000c0b6a in PyEval_EvalFrameEx () #10 0x00000001000c2d29 in PyEval_EvalCodeEx () #11 0x000000010003da80 in function_call () #12 0x000000010000c5e2 in PyObject_Call () #13 0x000000010001ebcb in instancemethod_call () #14 0x000000010000c5e2 in PyObject_Call () #15 0x00000001000ba5f7 in PyEval_CallObjectWithKeywords () #16 0x0000000100021e5e in PyInstance_New () #17 0x000000010000c5e2 in PyObject_Call () #18 0x00000001000be5f3 in PyEval_EvalFrameEx () #19 0x00000001000c2d29 in PyEval_EvalCodeEx () #20 0x00000001000c2e46 in PyEval_EvalCode () #21 0x00000001000e769c in PyRun_InteractiveOneFlags () #22 0x00000001000e78fe in PyRun_InteractiveLoopFlags () #23 0x00000001000e80e1 in PyRun_AnyFileExFlags () #24 0x00000001000fe77c in Py_Main () #25 0x0000000100000f14 in dyld_stub_strlen ()
On 4/26/12 11:50 AM, Marc Culler wrote:
Guessing that PIL was finding the System/Library/Frameworks/Tk.Framework instead of /Library/Frameworks/Tk.Framework, I tried hiding the system Tcl and Tk frameworks by renaming them. I was then able to create the PhotoImage and display it.
I don't know where those messages come from, and I have never encountered them before.
Sometimes Tk extension libraries will link against /System/Library/Frameworks instead of /Library/Frameworks when they are being compiled--this can cause the kinds of conflicts and crashes that you are seeing. The install_name_tool tool can re-link a binary to the correct framework, see the man page. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com
Kevin Walzer wrote:
Sometimes Tk extension libraries will link against /System/Library/Frameworks instead of /Library/Frameworks when they are being compiled--this can cause the kinds of conflicts and crashes that you are seeing. The install_name_tool tool can re-link a binary to the correct framework, see the man page.
Thanks, Kevin. That was the case with _imagingtk.so and install_name_tool fixed it. - Marc
In article <CALcZXRHT=M2=bfDVU_if1TN2M4Ktfw1U6HYjORchTwK5C8Se0Q@mail.gmail.com>, Marc Culler <marc.culler@gmail.com> wrote:
This was reported here in February, but no debugging information was provided by the reporter: http://stackoverflow.com/questions/9142786/python-imagetk-photoimage-segfaul... <view-source:http://stackoverflow.com/questions/9142786/python-imagetk-photoim age-segfault>
I can explain the nature of the problem, but I don't know how to fix it correctly.
I am using the standard x86_64 Python 2.7.2 package from python.org and I have installed Active State Tcl/Tk 8.11.
When I tried using easy_install to install PIL it would not load, claiming that _imaging.so did not exist. In fact, it existed but was only a thin i386 executable. So I compiled Imaging-1.1.7 with export CFLAGS='-arch i386 -arch x86_64' and export TCL_ROOT=/Library/Frameworks/Tcl.framework/Versions/8.5/Tcl
I was then able to load the module. However, the following code produced a segfault:
import Image import ImageTk import Tkinter W = Tkinter.Tk() Im = Image.open('test_image.jpg') x = ImageTk.PhotoImage(Im)
The crash occurs in Tk_GetImageMasterData. More importantly, though, the crash was preceded by the following messages:
objc[36554]: Class TKApplication is implemented in both /Library/Frameworks/Tk.framework/Versions/8.5/Tk and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined. objc[36554]: Class TKMenu is implemented in both /Library/Frameworks/Tk.framework/Versions/8.5/Tk and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.
This sounds like a know bug with XCode 3.2.6 described here: <https://discussions.apple.com/message/13314424?messageID=13314424#133144 24?messageID=13314424> The problem is an incorrect link to /Library/Frameworks. The following fix suggested by "Nertzius" worked for me: cd /Developer/SDKs/MacOSX10.6.sdk/Library; sudo mv Frameworks Frameworks-orig sudo mv Frameworks-orig/Frameworks . sudo rm -rf Frameworks-orig By the way, you can get an unofficial Mac binary installer for PIL, built for python.org python here: <http://www.astro.washington.edu/users/rowen/python/> -- Russell
I still have problem with this issue and I don't know what I'm doing wrong. objc[1296]: Class TKApplication is implemented in both /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and /Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined. objc[1296]: Class TKMenu is implemented in both /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and /Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined. objc[1296]: Class TKContentView is implemented in both /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and /Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined. objc[1296]: Class TKWindow is implemented in both /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and /Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined. Here is my otool -L Tk on both paths : on "/Library/Frameworks/Tk.framework/Versions/8.5" Tk: /Library/Frameworks/Tk.framework/Versions/8.5/Tk (compatibility version 8.5.0, current version 8.5.11) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0) /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 550.29.0) /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 15.0.0) /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 152.0.0) /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0) /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 625.0.0) /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 227.0.0) /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 44.0.0) /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 38.0.0) /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 751.29.0) /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1038.32.0) on /System/Library/Frameworks/Tk.framework/Versions/8.5 : Tk: /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk (compatibility version 8.5.0, current version 8.5.9) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.0.0) /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 629.0.0) /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 17.0.0) /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 153.0.0) /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0) /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0) /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 53.0.0) /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 41.0.0) /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 829.0.0) /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1125.0.0) and this is what I did: sudo install_name_tool -change /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk /Library/Frameworks/Tk.framework/Versions/8.5/Tk Tk but after that nothing changed at all. Can you provide me with more detail. I am not much familiar with Linker and C stuff. Thanks. -- View this message in context: http://python.6.n6.nabble.com/Segfault-in-Image-PhotoImage-on-OS-X-tp4931170... Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.
It's likely that a Tk or Python library is linking against one framework and Tk itself links against another. You'll have to run install_name_tool on the offending library. Sent from my iPhone On Nov 14, 2012, at 10:29 AM, llvllj <mohsen.jadidi@gmail.com> wrote:
I still have problem with this issue and I don't know what I'm doing wrong.
objc[1296]: Class TKApplication is implemented in both /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and /Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined. objc[1296]: Class TKMenu is implemented in both /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and /Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined. objc[1296]: Class TKContentView is implemented in both /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and /Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined. objc[1296]: Class TKWindow is implemented in both /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and /Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.
Here is my otool -L Tk on both paths :
on "/Library/Frameworks/Tk.framework/Versions/8.5"
Tk: /Library/Frameworks/Tk.framework/Versions/8.5/Tk (compatibility version 8.5.0, current version 8.5.11) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 550.29.0) /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 15.0.0) /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 152.0.0) /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0) /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 625.0.0) /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 227.0.0)
/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 44.0.0)
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 38.0.0)
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 751.29.0) /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1038.32.0)
on /System/Library/Frameworks/Tk.framework/Versions/8.5 :
Tk: /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk (compatibility version 8.5.0, current version 8.5.9) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.0.0)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 629.0.0) /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 17.0.0) /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 153.0.0) /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0) /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 53.0.0)
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 41.0.0)
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 829.0.0) /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1125.0.0)
and this is what I did:
sudo install_name_tool -change /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk /Library/Frameworks/Tk.framework/Versions/8.5/Tk Tk
but after that nothing changed at all. Can you provide me with more detail. I am not much familiar with Linker and C stuff. Thanks.
-- View this message in context: http://python.6.n6.nabble.com/Segfault-in-Image-PhotoImage-on-OS-X-tp4931170... Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss@python.org http://mail.python.org/mailman/listinfo/tkinter-discuss
participants (4)
-
Kevin Walzer -
llvllj -
Marc Culler -
Russell E. Owen