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
版权声明:本文标题:python - I cannot figure out why VS Code says Flask module not found - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741298404a2370946.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论