Simple material swap python script not working

Have you set Unreal’s built-in Python version to 3.X?
Your code looks like it is running in an environment other than Unreal Editor, so the header file cannot be found.