# Setting up a Sky: bpy.context.world = None

I am trying to set up a sky in my script using bpy.context.scene.world.use_sky_paper = True which results in the following error:

AttributeError: 'NoneType' object has no attribute 'use_sky_paper'


Why does bpy.context.scene.world return None? Is there some setup required for the world?

I encountered a similar problem, when trying to see which area is active via bpy.context.area.type where area is None.

Update: bpy.context.area is always None when running script headless.

• Your assignments working as expected for Blender 2.78c... Also context.area.type is never none. Cycles or Internal? What blender version? Are you trying to execute that commands headless (without UI)? – brockmann Aug 29 '17 at 8:54
• I am using blender 2.78 with internal render. I am not scripting inside blender but using an external python script executed with blender --background --python <name_of_script>. Executing print(bpy.context.area) prints None to the console. – McLawrence Aug 29 '17 at 9:05
• Since you are running these commands headless and bpy.context.area returns the active area of the UI, it's totally obvious why the property is none. Also I have no problems printing World.use_sky_paper to the command line. Does this example helps? – brockmann Aug 29 '17 at 9:22
• ok. So that part of my question is answered. The mode of the object is already object mode. The error persists when inserting bpy.ops.object.mode_set(mode='OBJECT') as suggested by the example. – McLawrence Aug 29 '17 at 10:10

If not set scene.world is None. Simply set it, for example to a world named "World" with scene.world = bpy.data.worlds.get("World") , or create a new one.

import bpy

scene = bpy.context.scene

if scene.world is None:
# create a new world
new_world = bpy.data.worlds.new("New World")
new_world.use_sky_paper = True
scene.world = new_world

• I am at the moment on another device: On my MacBook, it seems scene.world is already defined from the beginning. So I can check your solution only tomorrow. Any idea why that can depend on the PC, if blender version and script are the same? – McLawrence Aug 29 '17 at 16:34
• My guess would be to check startup.blend, you may have inadvertently removed world from scene. – batFINGER Aug 29 '17 at 16:44
• Solution works. Problem was indeed with startup.blender – McLawrence Aug 29 '17 at 16:51
• Is this a pre-2.8 fix? – Tango Mar 16 at 18:53