Python script not working beyond a certain line in the code
I have copy-pasted the code in blender and with few changes, same variable wrong names like TObjIRM and TOBjIRM for the same var, include import bmesh at beginning,... the code works now without errors.
This is what you want? ;) 

import bpy, bmesh
from mathutils import Matrix
from math import pi

class OrientLocalAxis(bpy.types.Panel):
    """Orients Local Axis to another Object without changing current 
Structual view"""
    bl_label = "Orient Local Axis to object"
    bl_idname = "OBJECT_PT_OLAxis"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    def draw(self, context):
        layout = self.layout
        scene = context.scene 
        obj = context.object 

        row = layout.row()
        row.label(text="Active object is: " + obj.name)             
        layout.prop_search(scene, "Epty", scene, "objects")

        row = layout.row()
        row.operator("object.align_local_axis")


def main(context):

    #-------------Obj = Object we want to change----------------------------
    #------------TObj = Target Object we want to Align to-------------------

    scene = bpy.context.scene
    TObj = scene.objects[scene.Epty]

    TObjIRE = TObj.rotation_euler
    TObjIRM = TObjIRE.to_matrix() 

    ObjIRE = bpy.context.active_object.rotation_euler
    ObjPos = bpy.context.active_object.location    
    # We will need this later for rotating the mesh
    ObjIRM = ObjIRE.to_matrix()

    #We Find out the Rotation Matrix to transform TObj to Obj---------------
    # We will use this transform the mesh back to its original orientation--

    ITM = ObjIRM  #ITM is for Inverse Transformation Matrix


    # We set the orientation of the Object to the target

    bpy.context.active_object.rotation_euler = TObjIRE

    #Now we go to Edit Mode and select all Vertices

    bpy.ops.object.mode_set(mode = 'EDIT')

    mesh = bmesh.from_edit_mesh(bpy.context.active_object.data)

    for v in mesh.verts: # Not sure if selection is needed Check Later
        v.select = True

    bpy.context.scene.objects.active = bpy.context.scene.objects.active

    bmesh.ops.rotate(mesh, cent=(0,1,0), matrix=TObjIRM, verts=mesh.verts)

    bpy.ops.object.mode_set(mode = 'OBJECT')


# Operator Definition

class AlignLocalAxis(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.align_local_axis"
    bl_label = "Align Local Axis"

    def execute(self, context):
        main(context)
        return {'FINISHED'}

 #--------------------------------------------------------------------------         
def register():
    bpy.utils.register_class(AlignLocalAxis)
    bpy.utils.register_module(__name__)
    bpy.types.Scene.Epty = bpy.props.StringProperty()

if __name__ == "__main__":
    register()