11

I am trying to run the following command on a 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

I've seen others have had a bus error in this situation. Does anyone know of a bug here or a way round it? I couldn't understand whether http://infohost.nmt.edu/tcc/help/pubs/pil/image-tk.html was relevant. Thanks!

I'm sorry to say the same thing happens even after upgrading 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
jtlz2
  • 7,700
  • 9
  • 64
  • 114
  • When does Segmentation fault occures? Try to save reference to image, e.g. `window.image = photo` – reclosedev Feb 04 '12 at 17:35
  • It doesn't get that far - the segfault is immediately after photo = ImageTk.PhotoImage(i), so I can't attempt window.image = photo. – jtlz2 Feb 04 '12 at 17:38
  • window.image=ImageTk.PhotoImage(i) also causes a segfault. – jtlz2 Feb 04 '12 at 17:39
  • This looks like the same issue? http://stackoverflow.com/questions/6147159/imagetk-photoimage-crash – jtlz2 Feb 04 '12 at 23:00
  • On another machine running Lion 10.7.2 the error is Segmentation fault: 11 – jtlz2 Feb 06 '12 at 10:15
  • Do you have imagemagick installed? As I recall Photoimage uses it. – Demosthenex Feb 10 '12 at 14:06
  • 'convert' works fine - is there a better way to check for imagemagick? – jtlz2 Feb 10 '12 at 16:44
  • Is this relevant? http://bugs.activestate.com/show_bug.cgi?id=83694 Kinda getting desperate here. – jtlz2 Feb 10 '12 at 16:49
  • I was curious if this happens for all JPEGs? And also if it happens on GIF, PNG, etc. – Mark Bennett Feb 11 '12 at 01:08
  • @user1021819 I have found this page on the net. --> http://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg682314.html It looks like the same issue on your code. I hope it helps you. – Alberto Solano Feb 11 '12 at 08:58
  • @user1021819 I know about the different version of python, try to downgrade the version as suggested in the link, maybe the problem will disappear. – Alberto Solano Feb 11 '12 at 09:33
  • @MarkBennett Good idea - it happens for a few different jpgs from different sources, as well as a png I tried. – jtlz2 Feb 11 '12 at 10:43
  • @AlbertoSolano thanks for this - a longstanding bug then.. Will next have a go at downgrading :) – jtlz2 Feb 11 '12 at 10:45
  • @user1021819 You are welcome. It's a really annoying bug! I hope you will solve.. ;-) – Alberto Solano Feb 11 '12 at 11:06
  • @AlbertoSolano Any idea how to retrieve the older version and actually install it? :) – jtlz2 Feb 11 '12 at 11:11
  • @user1021819 From what I understood, and, considering you didn't removed your Python 2.7 installation, read this question (replacing the version number you want) : http://superuser.com/questions/35256/how-can-i-change-the-default-python-version-on-snow-leopard – Alberto Solano Feb 11 '12 at 11:24
  • @user1021819 Remember the segmentation fault you have using tkinter, happens also for other *NIX distributions, such as your Mac. Because I don't have a Mac, but only an Ubuntu distribution and I don't know the command changes, I'm able to post you only that question. :) – Alberto Solano Feb 11 '12 at 11:30
  • you could ask on http://mail.python.org/mailman/listinfo/image-sig – noob oddy Feb 21 '12 at 23:01
  • You ask about a workaround. What are you trying to do? If all you need to do is display the image, then calling `i.show()` should work. – kuzzooroo Jul 04 '14 at 15:33

3 Answers3

2

If you are not using Apple's Tcl/Tk, try running otool -L on _imagingtk.so to see whether it is looking for its shared libraries in /System/Library. It should be looking in /Library, not /System/Library. If so, you can change the library search path with install_name_tool.

EdChum
  • 376,765
  • 198
  • 813
  • 562
Marc
  • 21
  • 2
  • How do I know if I'm using Apple's Tcl/Tk? If I'm using a standard Anaconda install, is that enough to figure out whether I am using Apple's Tcl/Tk? – kuzzooroo Jul 04 '14 at 15:23
1

Now fixed under

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.
jtlz2
  • 7,700
  • 9
  • 64
  • 114
1

Have you tried running Mac Python in 32 bit mode?

Look at the Fat Binary:

cd /usr/bin/
file python

I get:

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

To try 32 bit mode you would do:

arch -i386 /usr/bin/python

If that works, then it would at least be a workaround.

Mark Bennett
  • 1,446
  • 2
  • 19
  • 37
  • Unfortunately, this will require installing a ton of dependencies in order to run this under 32bit. I started to install a few, but gave up as it exploded exponentially on my system. – carl Feb 11 '12 at 18:22
  • Thanks Carl - exactly. I've emailed the EDP user list and am waiting to hear back from them. A shame no-one's gone for the bounty (for which many thanks!). – jtlz2 Feb 15 '12 at 09:05