Delete bone drivers from python

I’m trying to remove the junk bone drivers that Rigify leaves when extracting the ORG-* or DEF-* bones into a new armature (using Armature Deform addon), but I always recieve the error from driver_remove() method, stating that it won’t find the right path.
I’ve already checked over google (Stack Exchange, BArtists) and the best thing I’ve managed to find is the statement that this error is due to a bug here.

So before adding yet another hopefully innecessary bug report, I ask here: Any way to remove drivers from python?
bpy.ops.anim.channels_delete() is not useful to me, since it requires to be called from the Drivers window and I’m trying to stay in the 3D view (working on a workflow/pipeline little addon).

To reproduce, just make a single-bone armature and add a couple of drivers to, say, the scale, referencing to a custom property.

Here’s the code I’m using:

import bpy

object_drivers = bpy.context.active_object.animation_data.drivers
paths = []
items = object_drivers.items()

for driver in object_drivers: 
    paths.append(driver.data_path)


for i, fcurve in enumerate (object_drivers):    #trying different methods to get the damn path
    fcurve.driver_remove(paths[i])
#    fcurve.driver_remove(items[i][1].driver.variables[0].targets[0].data_path)
#    fcurve.driver_remove(object_drivers[i].data_path)

Thanks a bunch in advance!

Seems like you’re trying to remove the driver from itself? You want to remove it from the actual bone/pose_bone. Also, data_path will return the full path, when driver_remove on the pose bone doesn’t need the full path. So for scale, data_path returns “pose.bones[‘Bone’].scale”, but you would only need the “scale” from that(relative path?), i.e. :


bone = bpy.data.objects['Armature'].pose.bones["Bone"]
bone.driver_remove('scale')