Move bone to a certain location python I have a bone and two empties, how in edit mode I can move the head of the bone to the location of empty1 and the tip to the location of empty2 using python?

I'm trying the below script but it doesn't work as I want it to move to the empty location as highlighted below.

import bpy

bpy.ops.object.select_all(action='DESELECT')
obj = bpy.data.objects['metarig']
obj.select = True
bpy.context.scene.objects.active = obj
bpy.ops.object.mode_set(mode='EDIT')
emp = bpy.data.objects['Empty']
for bone in obj.data.edit_bones:
    if bone.name == 'hips':
        bone.head = emp.location


My .blend file can be found here:
Calculate the local coordinates by applying the inverse matrix of the armature to the global coordinates.

# obj       the armature (scaled)
# emp       the empty in world space (no parent)

bone.head =  obj.matrix_world.inverted() * emp.location