Import Error (Unknown Location). I'm still pretty new to python, please how do I fix this?

Hello and welcome to the forum @Jeffrey

Your import is not correct.

# You need at least this import for a start.
from flask import Flask

# Instantiate the class with "app"
app = Flask(__name__)

@app.route('/')
def index():
    return "My first flask website." 

if __name__ == "__main__"":
    app.run(debug = True)

I guess this is a minimum to have this working.
While building the app you need more imports.
Like render_template, url_for and more.

I suggest you create a virtual enviornment for this if you haven’t done so yet.
If that is not yet covered in the exercise you are at now I guess it will be next.
Do not skip that part.

1 Like

Thanks for the response. I already did that in a different module which I stored in a folder (Flash_blog), I’m trying to import it, but for some reason it’s not locating the package folder.

Hello @Jeffrey

If you don’ t already have this you should create a empty file called:

__init__.py

This helps Python to find modules to be imported

1 Like

Ok, so first up, the best way to do a screenshot is with cmd-shift-4 on a mac, or Snipping Tool on windows. Your phone will always be off angle and makes it harder to see. You can also select your code or the output of terminal and paste it here like this:

[code]
# your paste here
[/code]

Next up, you are in a folder named blog as I can see from your screenshot it’s C:\Users\PC\Documents\blog. Inside that folder you need a folder (aka directory) named Flask_blog, and inside that you need Flask_blog/__init__.py. That’s TWO underscores init TWO underscores dot py.

Try that, then you can try setting the PYTHONPATH like this:

$env:PYTHONPATH = "."

The "." simply says “right here in whatever directory I’m in”.

1 Like

Thank you! It worked.
I really appreciate it.

Can you be explicit about what worked? That’ll help the next person.