Opened 16 years ago

Closed 16 years ago

Last modified 15 years ago

#15706 closed defect (fixed)

matplotlib segfault

Reported by: tom.duck@… Owned by: skymoo (Adam Mercer)
Priority: Normal Milestone:
Component: ports Version: 1.6.0
Keywords: matplotlib segfault Cc:
Port:

Description

I have a fresh MacPorts install on 10.4 Tiger. Using a standard install of py25-matplotlib (no variants) the example matplotlib programs installed in /opt/local/share/py25-matplotlib/examples/pylab all segfault after bringing up an empty X-window. e.g.:

--

$ cd /opt/local/share/py25-matplotlib/examples/pylab

$ python2.5 axes_demo.py

Segmentation fault

--

I had first thought this might be a tk problem, but the attached python/tk test program appears to work.

I am not sure how to isolate this bug further, but am willing to help.

Attachments (3)

test.py (499 bytes) - added by tom.duck@… 16 years ago.
python/tk test program
python.crash.log (20.0 KB) - added by tom.duck@… 16 years ago.
python.crash.log from ~/Library/Logs/CrashReporter
patch-setupext.py.diff (3.2 KB) - added by skymoo (Adam Mercer) 16 years ago.
updated patch-setupext.py.diff - take 2

Download all attachments as: .zip

Change History (40)

Changed 16 years ago by tom.duck@…

Attachment: test.py added

python/tk test program

comment:1 Changed 16 years ago by skymoo (Adam Mercer)

Milestone: Port Bugs
Owner: changed from macports-tickets@… to ram@…
Status: newassigned

comment:2 Changed 16 years ago by skymoo (Adam Mercer)

I can reproduce this, I'm investigating. Strange as I had reports a while ago of segfaults when using interactive backends but couldn't reproduce them then.

Can you try using the wxpython and gtk2 interactive variants.

comment:3 Changed 16 years ago by skymoo (Adam Mercer)

I've just tried with the wxpython and gtk2 variants and the axes_demo.py example runs without error. I then reinstalled the default tkinter variant and it worked!

Can you try uninstalling and reinstalling again?

comment:4 in reply to:  3 ; Changed 16 years ago by tom.duck@…

Replying to ram@macports.org:

I've just tried with the wxpython and gtk2 variants and the axes_demo.py example runs without error. I then reinstalled the default tkinter variant and it worked!

Can you try uninstalling and reinstalling again?

I am still stuck on getting it to work with wxpython. Apparently I need pythonw, but this doesn't appear to have been installed. Is this a missing dependency? Note that I am using python 2.5 otherwise. Here is the error message:

$ python axes_demo.py

This program needs access to the screen.

Please run with 'pythonw', not 'python', and only when you are logged in on the main display of your Mac.

comment:5 in reply to:  4 ; Changed 16 years ago by skymoo (Adam Mercer)

Are you sure you're using the MacPorts python? What's the output of

$ python --version

comment:6 in reply to:  5 Changed 16 years ago by tom.duck@…

Replying to ram@macports.org:

Are you sure you're using the MacPorts python? What's the output of

$ python --version

Yes. Sorry for the confusion. I get the same output running python2.5 directly. "python" is a simlink to the ports version:

$ which python

/usr/bin/python

$ ls -al /usr/bin/python

lrwxr-xr-x 1 root wheel 24 Jun 21 11:24 /usr/bin/python@ -> /opt/local/bin/python2.5

$ python --version

Python 2.5.2

comment:7 Changed 16 years ago by skymoo (Adam Mercer)

You should not overwrite the /usr/bin/python symlink as doing so will break a lot of things - such as Automator. You should install the python_select port to manage the python symlink.

I can't understand why you're getting the error as I don't:

$ port installed py25-matplotlib
The following ports are currently installed:
  py25-matplotlib @0.98.0_0+wxpython (active)
$ which python
/opt/local/bin/python
$ python --version
Python 2.5.2
$ python /opt/local/share/py25-matplotlib/examples/pylab/axes_demo.py
$

and the plot is displayed without error.

The only thing that I can suggest is to restore the system python symlinks, install python_select, run

$ python_select python25

to set the default python to be the MacPorts version and try again.

comment:8 in reply to:  7 Changed 16 years ago by tom.duck@…

Very strange. I followed your instructions and the problem persists. The error message is quite weird.

Maybe this has something to do with my X setup? I will look into that later today.

$ sudo python_select python25
Selecting version "python25" for python

$ port installed py25-matplotlib
The following ports are currently installed:
  py25-matplotlib @0.98.0_0+wxpython (active)

$ which python
/opt/local/bin/python

$ python /opt/local/share/py25-matplotlib/examples/pylab/axes_demo.py
This program needs access to the screen.
Please run with 'pythonw', not 'python', and only when you are logged
in on the main display of your Mac.

comment:9 Changed 16 years ago by skymoo (Adam Mercer)

Is X11.app running?

comment:10 in reply to:  9 Changed 16 years ago by tom.duck@…

Yes. However, I think my earlier speculation was wrong anyway: If I remember correctly, wx accesses the native display capabilities on each system, so X should not be needed here (I think). The error message appears to say as much:

$ python --version
Python 2.5.2

$ python axes_demo.py 
This program needs access to the screen.
Please run with 'pythonw', not 'python', and only when you are logged
in on the main display of your Mac.

Note also that X is working fine with the imagemagick 'display' program installed using port. In any event, turning X.app on or off makes no difference to this problem.

If I understand correctly, pythonw is what you used to have to run (python2.3 and earlier) to access the native display capabilities. So, why isn't my python2.5 install able to do that? I am wondering if you perhaps have one of the python25 variants installed? Universal, or some such thing?

comment:11 Changed 16 years ago by skymoo (Adam Mercer)

These are the versions of the relevant ports I have installed:

$ port installed python25 py25-matplotlib
The following ports are currently installed:
  py25-matplotlib @0.98.0_0+wxpython (active)
  python25 @2.5.2_2+darwin_9 (active)
$ 

So I'm not installing any special variant of python25. Sounds like something isn't quite right with your python25 installation.

comment:12 in reply to:  11 Changed 16 years ago by tom.duck@…

I wiped out my macports installation (I had only recently started working with it), installed the most recent Xcode (mine was maybe a year old), then installed python25, py25-matplotlib, dependencies, and a few other things (like python_select). Unfortunately, the exact same problems persist with matplotlib for both tkinter and wxpython.

Here is the output from my system to compare with what you showed, ram. There is a difference in that I am running 10.4 Tiger and so have the darwin_8 variant of python25 installed. The portfile shows an extra compile flag for the darwin_9 variant. Is there something similar missing for darwin_8?

$ port installed python25 py25-matplotlib
The following ports are currently installed:
  python25 @2.5.2_2+darwin_8 (active)
  py25-matplotlib @0.98.0_0+tkinter
  py25-matplotlib @0.98.0_0+wxpython (active)

comment:13 Changed 16 years ago by skymoo (Adam Mercer)

That extra flag is due to Leopard being a UNIX03 certified platform, and is not needed on other platforms. I suspect that the problems you're seeing, especially with the wxpython variant is related to python, not matplotlib, but I can't understand why the tkinter variant is segfaulting.

comment:14 in reply to:  13 Changed 16 years ago by tom.duck@…

OK, thanks for the info about the flag.

Note that the test program that I gave at the beginning for python/tk is still working. This suggests that python may not be the problem in the tkinter case.

I should also mention that I have had this all working under fink (currently disabled and archived), and so I don't think that there is some weird underlying problem in my system. I will keep trying new ideas as they come up.

comment:15 Changed 16 years ago by tom.duck@…

This issue with pythonw and wx has a ticket, and is apparently still outstanding: see http://trac.macports.org/ticket/12817.

I have tried the test python/wx program and it fails in the same way I have with matplotlib+wxpython:

$ python test2.py
This program needs access to the screen.
Please run with 'pythonw', not 'python', and only when you are logged
in on the main display of your Mac.

I am wondering if you perhaps have another python install (say 2.4?) that provides pythonw? If so, this may shed some light on why your python+tkinter is actually working -- i.e., missing dependencies -- whereas my bare-bones install is not.

comment:16 Changed 16 years ago by raimue (Rainer Müller)

Please note that pythonw (or pythonw2.5) is currently not provided by the python2.5 port. python24 already provides pythonw2.4.

It will need the new port building as a framework I put together on a separate branch. I proposed them for testing on macports-dev and I am looking forward to merge them back to trunk very soon.

Adam, are you using /usr/bin/pythonw on Leopard?

comment:17 Changed 16 years ago by skymoo (Adam Mercer)

No I'm using /opt/local/bin/python and as such I can't understand why its working for me.

Is there an ETA for merging the branch?

comment:18 Changed 16 years ago by skymoo (Adam Mercer)

Sorry I should of added that this is a symlink to /opt/local/bin/python2.5 created using python_select

comment:19 Changed 16 years ago by skymoo (Adam Mercer)

The new framework builds of python has been merged onto the trunk, these now provide pythonw for python25. Can you upgrade to these and try again? You'll also need to rerun:

$ sudo python_select python25

comment:20 in reply to:  19 Changed 16 years ago by tom.duck@…

FANTASTIC: py25-matplotlib+wxpython works when I run the axes_demo.py program (and others) in /opt/local/share/py25-matplotlib/examples/pylab/.

py25-matplotlib+tkinter still produces a segfault after popping up an X-window frame. Is there a way to reveal the compilation process that port hides (e.g., logfiles)? That might provide some helpful clues toward correcting the problem.

In the mean-time perhaps the wxpython variant should be set as the default.

Note that the uninstall process for python was complicated because port doesn't currently uninstall dependencies. This bug is already ticketed at http://trac.macports.org/ticket/8431.

comment:21 Changed 16 years ago by skymoo (Adam Mercer)

Last time this tkinter segfault came up there was no indication in the build log as to what went wrong. There should be a crash log in $HOME/Library/Logs/CrashReporter that will detail the segfault. If you can attach that to the ticket I can try and get some info from upstream.

Changed 16 years ago by tom.duck@…

Attachment: python.crash.log added

python.crash.log from ~/Library/Logs/CrashReporter

comment:22 Changed 16 years ago by tom.duck@…

I moved the old crash log out of the way before creating the attached one.

comment:23 Changed 16 years ago by tom.duck@…

I may have found something.

The crash log indicates that the crash occurs in com.tcltk.tcllibrary and com.tcltk.tklibrary. The locations for these libraries is given at the bottom of the log:

0x9aa2f000 - 0x9aaadfff com.tcltk.tcllibrary 8.4.7 a    /System/Library/Frameworks/Tcl.framework/Versions/8.4/Tcl
0x9aac7000 - 0x9ab76fff com.tcltk.tklibrary 8.4.7 a     /System/Library/Frameworks/Tk.framework/Versions/8.4/Tk

Shouldn't these items reference the libraries that MacPorts has built, rather than what comes with OS X? The choice seems odd given that matplotlib+tkinter is listed as dependent on the MacPorts versions of tcl and tk (via py25-tkinter).

Library detection is performed in the setupext.py file of the py25-matplotlib build (search for 'framework'). Note that once it finds the OS X versions in /System/Library/Frameworks, it stops looking further.

comment:24 Changed 16 years ago by skymoo (Adam Mercer)

Good catch, I'll get a patch together. Thanks!

comment:25 Changed 16 years ago by skymoo (Adam Mercer)

I've just attached an updated patch-setupexy.py.diff that removes the list of directories to check for a framework build of Tcl and Tk as the MacPorts Tcl/Tk is not a framework build. Can you copy this into the py25-matplotlib/files directory and try rebuilding. It builds, and works, fine for me on Intel Leopard

sudo port uninstall py25-matplotlib
sudo cp patch-setupext.py.diff `port dir py25-matplotlib`/files
sudo port install py25-matplotlib

should do the trick.

comment:26 Changed 16 years ago by tom.duck@…

Not quite there, I think.

When I run the test program, it brings up a window but not using Tk/X. It looks like Wx to me.

If you try to force matplotlib to use Tk, here is what happens:

$ python axes_demo.py -dTKAgg
Traceback (most recent call last):
  File "axes_demo.py", line 3, in <module>
    from pylab import *
  File "/opt/local/lib/python2.5/site-packages/pylab.py", line 1, in <module>
    from matplotlib.pylab import *
  File "/opt/local/lib/python2.5/site-packages/matplotlib/pylab.py", line 246, in <module>
    from matplotlib.pyplot import *
  File "/opt/local/lib/python2.5/site-packages/matplotlib/pyplot.py", line 39, in <module>
    new_figure_manager, draw_if_interactive, show = pylab_setup()
  File "/opt/local/lib/python2.5/site-packages/matplotlib/backends/__init__.py", line 24, in pylab_setup
    globals(),locals(),[backend_name])
  File "/opt/local/lib/python2.5/site-packages/matplotlib/backends/backend_tkagg.py", line 8, in <module>
    import tkagg                 # Paint image to Tk photo blitter extension
  File "/opt/local/lib/python2.5/site-packages/matplotlib/backends/tkagg.py", line 1, in <module>
    import _tkagg
ImportError: No module named _tkagg

So it would appear that the _tkagg extension module is not getting built.

comment:27 Changed 16 years ago by skymoo (Adam Mercer)

Damn, I'll have to dig a little deeper into the build process.

Changed 16 years ago by skymoo (Adam Mercer)

Attachment: patch-setupext.py.diff added

updated patch-setupext.py.diff - take 2

comment:28 Changed 16 years ago by skymoo (Adam Mercer)

Right I've uploaded another updated patch-setupext.py-diff, can you see how this works for you? It seems like the correct Tcl/Tk is getting picked up on build this time:

Tkinter: Tkinter: 50704, Tk: 8.5, Tcl: 8.5

comment:29 in reply to:  28 Changed 16 years ago by tom.duck@…

Very, very close.

If I do

$ python axes_demo.py -dTKAgg

it brings up an X window, sure enough. However, if I do just

$ python axes_demo.py

then it seems to default to a Wx window, which should not be happening for the tkinter variant.

Note that although I have the Wx components installed, I have not installed the wxpython variant of py25-matplotlib.

Almost there!

comment:30 Changed 16 years ago by skymoo (Adam Mercer)

Great!

Do you have a .matplotlib/matplotlibrc file? If so what is the backend set to?

If not what is the backend in /opt/local/lib/python2.5/site-packages/matplotlib/mpl-data/matplotlibrc set to?

comment:31 in reply to:  30 Changed 16 years ago by tom.duck@…

Do you have a .matplotlib/matplotlibrc file?

No.

If not what is the backend in /opt/local/lib/python2.5/site-packages/matplotlib/mpl-data/matplotlibrc set to?

backend      : WXAgg

Is this not what is in the MacPort sources? I did not change it.

It sounds like the problem is basically solved... :o)

comment:32 Changed 16 years ago by skymoo (Adam Mercer)

The version of matplotlibrc distributed with matplotlib contains TkAgg as the default interactive backend, so that explains why WxAgg is used in preference to TkAgg. I should be able to commit this patch tomorrow, thanks a lot for your help in solving this.

comment:33 Changed 16 years ago by tom.duck@…

Thanks for your efforts too!

I will continue to work my way through the install process, and will submit tickets when things come up.

I have also created a local port for py25-tables which I will submit soon. I hope that this isn't stepping on anyone's toes...

comment:34 Changed 16 years ago by skymoo (Adam Mercer)

Not at all, I'll keep a look out for the port - or if you want assign the icket to me and I'll get it committed.

I'm planning on committing the fix for this bug tomorrow.

comment:35 Changed 16 years ago by tom.duck@…

Here it is. I submitted it before I saw your note:

https://trac.macports.org/ticket/15771

comment:36 Changed 16 years ago by skymoo (Adam Mercer)

Resolution: fixed
Status: assignedclosed

fixed in r37908

comment:37 Changed 15 years ago by (none)

Milestone: Port Bugs

Milestone Port Bugs deleted

Note: See TracTickets for help on using tickets.