I was able to fix this by adding the following line:
bpy.context.scene.render.engine = 'CYCLES'
This works fine for me as I need to use the cycles engine anyways
I'm writing a standalone python script to render .OBJ files automatically, without a .blend file or anything. I installed bpy 2.82 on my windows machine using the instructions found here. And I have python 3.7.9 installed.
Currently, as just a test to get my bearings, I tried the following code to try to setup a simple scene, load in a .OBJ, and render it out:
import bpy import os from math import radians maplet_path = 'obj_files\\bunny.obj' image_out_path = 'render.png' # Create a Scene: scene = bpy.data.scenes.new("Scene") camera_data = bpy.data.cameras.new("Camera") light_data = bpy.data.lights.new(name="Light", type='SUN') # Import the maplet data: local_path = os.getcwd() bpy.ops.import_scene.obj(filepath=os.path.join(local_path,maplet_path)) scene.render.filepath = os.path.join(local_path,image_out_path) scene.render.image_settings.file_format='PNG' # Get handles for all objects: maplet = bpy.context.selected_objects scene = bpy.data.scenes.new("Scene") camera = bpy.data.objects.new("Camera", camera_data) sun = bpy.data.objects.new(name="Light", object_data=light_data) # Setup camera parameters: scene.render.resolution_x = 1920 scene.render.resolution_y = 1080 camera.location = (-2.0, 3.0, 3.0) camera.rotation_euler = ([radians(a) for a in (422.0, 0.0, 149)]) # Setup scene: sun.location = (2.0,2.0,2.0) sun.rotation_euler = (radians(10), radians(15), radians(20)) maplet.location = (0,0,0) maplet.rotation_euler = (0,0,0) # Add camera to the scene: scene.camera = camera # Update the scene: bpy.context.view_layer.update() # Render: bpy.ops.render.render("EXEC_DEFAULT",write_still=True) bpy.data.images['Render Result'].save_render(os.path.join(local_path,image_out_path)) print('hi')
Unfortunately, the program runs perfectly fine, but once it gets to the line:
it hangs for a moment, and then just exits. It never prints 'hi', and it never writes any image. It also doesn't print out any errors or anything else, it just stops running.
I tried stepping through with pdb and it appears to hang/fail at:
c:\......\python\python37\2.82\scripts\modules\bpy\ops.py(182)idname_py()-'render.render' -> return self._module + "." + self._func
Is there something wrong with how I went about installing bpy? Or something wrong with the script I've written?
import bpyfollowed by
bpy.ops.render.render()? Just checked (have bpy 2.90.2 built against python 3.8.2 (ubuntu) and that simple test segfaults) $\endgroup$
bpy.context.scene.render.engine = 'CYCLES'to the script. Which is a desireable fix for me anyways, since I want to be using cycles for this project anyways. Unsure if that'll help those looking for eevee $\endgroup$