Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Segfault when calling LayoutView() in Python script


I am trying to save an image with LayoutView.save_image()
But merely creating a new LayoutView object results in a segmentation fault (ERROR: Signal number: 11).

I use Klayout 0.25.9 (installed with the deb file from in a fully updated Ubuntu 18.04 LTS VM to call the Python script in interpreter mode:

klayout -z -nc -r /path/to/

import pya

#Test if calling LayoutView() works
lv = pya.LayoutView()  #This causes the seg fault

I have uploaded the full error message and the log of valgrind from running valgrind klayout -z -nc -r /path/to/ .. >valgrind.log 2>&1 to Github.
Issue #289 is on Github already, but I thought discussing it in the forum as well might be a good idea.
It may of course be an error on my part. If so, I would be thankful for advice on saving a PNG image with a Python script other than:

import pya
layout = pya.Layout()'filename.gds')
lv = pya.LayoutView()
lv.create_layout(lv, True)
lv.save_image('filename.png', 500, 500)

Any help would be highly appreciated :-)



  • Hi,

    I see that a segfault isn't really a nice way of saying "don't do it this way".

    The right way is do let the main window create a view

    main_window = pya.MainWindow.instance()
    view_index = main_window.create_view()
    view = main_window.view(view_index)   # the LayoutView object

    A view can be a Widget embedded into other widgets, but it has a parent in this case. I guess the segfault is because there is no such parent.


  • Thank you so much!
    That worked :smile:


Sign In or Register to comment.