bpy has to be imported inside the script