I am also getting this error. Unfortunately, I cannot always put my code within an if __name__ == '__main__'.
if __name__ == '__main__'