3
$\begingroup$

This used to work perfectly with 2.92 but now fails with 3.0

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

with message TypeError: cannot unpack non-iterable NoneType object

Is there some change I can't find the docs to?

$\endgroup$

1 Answer 1

4
$\begingroup$

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]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.