Are you running the notebook interactively or with a Service Principal?
You will get the error
## Not In PBI Synapse Platform ##
when running a notebook using Service Principal and you are using Sempy. Also some properties of notebookutils.runtime.context will return None, like WorkspaceName and UserName.
I wrote about this a blog post which you will find here: Who's Calling? Understanding Execution Context in Microsoft Fabric