Because cycles_preferences.get_devices()
is returning None
. You want cycles_preferences.devices
instead. But that may fail with a different error if you have more than two entries in devices
. On my system, that's currently returning 3 devices.
If you try get_devices
and a Tab for completion in the Python console you get this:
>>> cycles_preferences.get_devices(
get_devices(self, compute_device_type='')
# Deprecated: use refresh_devices instead.
But further investigation says that just updates the device list. So your code should probably be
preferences = bpy.context.preferences
cycles_preferences = preferences.addons["cycles"].preferences
cycles_preferences.refresh_devices()
cuda_devices = cycles_preferences.devices[0]
opencl_devices = cycles_preferences.devices[1]