I am using Blender as Python Module on Mac and now attempting to create a scene programmatically and take a screenshot of what the camera sees but I am getting a "Segmentation Fault: 11" when running the following script (on calling bpy.ops.render.render).

import bpy
import mathutils
import bmesh

scene = bpy.context.scene

# Create the cube
mesh = bpy.data.meshes.new('cube')
ob = bpy.data.objects.new('cube', mesh)
bm = bmesh.new()
bmesh.ops.create_cube(bm, size=1.0)

# Create a light
light_data = bpy.data.lights.new('light', type='POINT')
light = bpy.data.objects.new('light', light_data)
light.location = mathutils.Vector((3, -4.2, 5))

# Create the camera
cam_data = bpy.data.cameras.new('camera')
cam = bpy.data.objects.new('camera', cam_data)
scene.camera = cam

cam.location = mathutils.Vector((6, -3, 5))
cam.rotation_euler = mathutils.Euler((0.9, 0.0, 1.1))

# Render settings
scene.render.image_settings.file_format = 'PNG'

filepath = "/tmp/image_blender.png"

# Segmentation fault caused by this line
bpy.ops.render.render(write_still = 1)

img = bpy.data.images['Render Result']
img.save_render(filepath, scene=scene)

I'd love to get some help and understand if there's an issue with the script or with the way I installed/configured Blender as a python module. Thanks in advance!

P.S.: Copy/Paste of Problem Detail and System Configuration

  • 1
    $\begingroup$ I can't reproduce a crash. It could be that something went wrong when building Blender as python module. Without a stack trace it's hard to tell what exactly went wrong. $\endgroup$ – Robert Gützkow Dec 23 '19 at 11:25
  • $\begingroup$ Ditto. Can confirm no hassle either. Albeit I'm on Ubuntu, python 3.7.5, version 2.8.2 built from master. Is it Ok running in blender background mode? $\endgroup$ – batFINGER Dec 23 '19 at 13:17
  • $\begingroup$ Thanks @RobertGützkow! I have added a link to what was generated by the mac. Not sure if it's useful. $\endgroup$ – Many Jeans Dec 23 '19 at 13:58
  • $\begingroup$ @batFINGER: can you clarify what you mean by running in bender background mode? $\endgroup$ – Many Jeans Dec 23 '19 at 13:59
  • $\begingroup$ blender -b from the command prompt. docs.blender.org/manual/en/latest/advanced/command_line/… $\endgroup$ – batFINGER Dec 23 '19 at 14:05

I experienced this same error with the bpy module on MacOS 10.15, python 3.7.7 and blender 2.83/2.82

I was able to fix it by changing to a different renderer.

you can add this line: bpy.context.scene.render.engine = 'CYCLES'

before: bpy.ops.render.render(write_still = 1)

And it will no longer seg fault

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.