Set active bone in pose mode from Python script
Set bpy.types.ArmatureBones.active

It's a matter of setting the active bone of the armature (the data part), and hence the active pose bone.

Python console code. An armature object is active and in pose mode. Long windedly sets the active bone.

&gt;&gt;&gt; C.object
bpy.data.objects['Armature']

&gt;&gt;&gt; C.object.data
bpy.data.armatures['Armature']

&gt;&gt;&gt; C.object.data.bones["Bone"]
bpy.data.armatures['Armature'].bones["Bone"]

&gt;&gt;&gt; C.object.pose.bones["Bone"]
bpy.data.objects['Armature'].pose.bones["Bone"]

&gt;&gt;&gt; C.object.pose.bones["Bone"].bone
bpy.data.objects['Armature'].pose.bones["Bone"].bone

&gt;&gt;&gt; C.object.data.bones["Bone"] == C.object.pose.bones['Bone'].bone
True

&gt;&gt;&gt; bone = C.object.pose.bones["Bone"].bone
&gt;&gt;&gt; C.active_pose_bone
bpy.data.objects['Armature'].pose.bones["Bone.001"]

&gt;&gt;&gt; C.object.data.bones.active
bpy.data.armatures['Armature'].bones["Bone.001"]

&gt;&gt;&gt; C.object.data.bones.active = bone
&gt;&gt;&gt; C.object.data.bones.active
bpy.data.armatures['Armature'].bones["Bone"]

&gt;&gt;&gt; C.active_pose_bone
bpy.data.objects['Armature'].pose.bones["Bone"]


Use bone.select = True to have bone both active and selected.

Note There is no need for the operator.

Example adds a copy rotation constraint to each selected pose bone.  The cube is used as the constraint target.  Run script in pose mode, else context.selected_pose_bones will be None

import bpy

context = bpy.context
scene = context.scene
cube = context.scene.objects.get("Cube")

if cube and context.object.mode == 'POSE':
    for pb in context.selected_pose_bones_from_active_object:
        # use if already existes, else create
        cr = (pb.constraints.get("CubeRot")
                or pb.constraints.new(type='COPY_ROTATION'))
        # set some properties
        cr.name = "CubeRot"
        cr.target_space = 'LOCAL'
        cr.target = cube