admin管理员组

文章数量:1278882

I have VS Code, Windows 11, Python 3.13. I just reinstalled python and VS Code.

I created a new workspace folder. Created new virtual environment, selected interpreter. Ran .\.venv\Scripts\activate in the terminal. Now, the first time I ran this, I had to open PowerShell and change the ExecuationPolicy for the user.

I create a file: app.py, from terminal pip install flask.

In app.py:

from flask import Flask
from flask_scss import Scss
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)


@app.route("/")
def index():
    return "testing"


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

There are no IntelliSense issues in the IDE, but when I run the file, I get:

[Running] python -u "c:\Users\USER1\Documents\Ranger Project\Ranger_02\app.py" 
File "c:\Users\USER1\Documents\Project\Project_02\app.py", line 1, in <module>
    from flask import Flask
ModuleNotFoundError: No module named 'flask'

I have tried the following: Deactivating the venv, going "global".
Selecting a different interpreter. Installed python 3.12. Tried the same things. Mutiple times going between venv and out of venv.

Then I reinstalled everything.

I found a checklist someone created for troubleshooting, here

The funny thing is, whether I run pip list within or outside the venv, I get the same package list. Now, at work, I am pretty sure the two are separate. I can have a minimal list globally, and install whatever I need in the venv. But for some reason it is not working for me here at home.

My thought is that there must be something to do with the permissions, or perhaps which Environment Variable was modified, or maybe something to do with a path on install, but I am not sure.

I fot to mention that if I run flask --version in the terminal, I get: Python 3.13.2 Flask 3.1.0 Werkzeug 3.1.3

I did go through several VERY OLD posts on this topic. One mentions a flask shell, not sure if that applies to Windows VS Code or not.

Ok, I just found one from 4 years ago here.

I run the file by clicking the arrow in the top right. But, taking advice from the above link, I type python app.py in the terminal and it ran.

So, even though I select different interpreters, I cannot "click to run" the file. Why is this and how can I solve it?

本文标签: pythonI cannot figure out why VS Code says Flask module not foundStack Overflow