I am using the book: Head First Python A Brain-Friendly Guide by Paul Barry and I’m up on the chapter on building a webapp. I created a little app called “flask” that would print “Hello World.” Unfortunaly, when I tried to use the following command: py -3 flask.py, I get the following error:
ImportError: cannot import name ‘flask’ from partially initialized module ‘flask’ (most likely due to a circular import)
Your program tries to import the flask module, but you’ve given your program the same name “flask.py”, so your program is instead trying to import itself.
You might have a flask.pyc sitting around from the previous attempt. Look in the same directory as flask.py and also in the __pycache__ directory (if one exists). Remove any flask.pyc that you find, then try again.
That should fix the problem and let you use hello_flask.py safely.
Which name is undefined? It would be helpful if you copied and pasted the traceback. Is it saying that _name_ is undefined? Did you mean __name__? That’ll be '__main__' unless the file is imported, so it’s probably not what you want anyway.
Also, when posting code or tracebacks, please ensure that it’s displayed formatted by selecting the code or traceback text when you enter it and then click the </> button.