Trying to run a webapp

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)

What does that mean and how do I fix it?
mlk

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.

O.k. I got that. But when I tried to rename it, I still get the error.

What is the new name? Are you sure you haven’t renamed it to conflict with another module, or have 2 files trying to import each other?

I tried renaming to hello_flask.py and still get the same error. Here’s the app that I’m trying to run in the cmd:

from flask import flask

app = Flask(name)

@app.route(‘/’)
def hello() → str:
return ‘Hello world from Flask!’

app.run()

I am finding that cmd is too hard to use as I can’t get anything to work on it.
mlk

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.

Try from flask import Flask instead.

Got a little further after making the change. Now, I’m getting a name not defined error.
mlk

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.

Got it to work that time. It’s hard to tell wheather it’s a _ or __.
mlk