# Compute Device Selection for a shared Blender Version

I am writing python scripts in blender for a team of 3D-Artists. The scripts and the blender version are on a network drive "R:". When calling the script

R:\blender-2.82a\blender.exe -b --python-expr "import bpy; print(bpy.context.preferences.addons['cycles'].preferences.devices.keys());"


The output for everybody is:

['GeForce GTX 1050', 'AMD Ryzen 5 3400G with Radeon Vega Graphics']


Which are my devices. The 3D-Artists have other devices. Can it be that the devices listed in the cycles addon are not derived at runtime? Or how could that happen? I want to activate the gpu for every 3D-Artist respectively, based on their own hardware.

Best, Manuel

• You haven't retrieved the current list of devices through get_devices(). See this answer for reference. Note that the answer hasn't been updated to include OptiX. – Robert Gützkow Jun 17 at 13:22

Okay. Robert's answer was the key. Apparently the array in bpy.context.preferences.addons['cycles'].preferences.devices holds all devices that have ever been activated and saved in the blender gui. In order to get the current hardware and to update the devices array, you call:

preferences = bpy.context.preferences.addons['cycles'].preferences
cuda_devices, opencl_devices = preferences.get_devices()


And then you do something like:

gpu_device = None

for device in preferences.devices:
device.use = False #reset all other devices
if device.type == "CUDA" and device in cuda_devices:
gpu_device = device

bpy.context.scene.cycles.device = "GPU"