Segmentation Fault when calling bpy.ops.render.render (script using Blender as a Python Module on Mac) 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)
scene.collection.objects.link(ob)
bm = bmesh.new()
bmesh.ops.create_cube(bm, size=1.0)
bm.to_mesh(mesh)
bm.free()

# Create a light
light_data = bpy.data.lights.new('light', type='POINT')
light = bpy.data.objects.new('light', light_data)
scene.collection.objects.link(light)
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.collection.objects.link(cam)
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
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