How to add a python path to a virtual environment in visual studio code?

I built a flask project application in visual studio code, including a very simple flask application:

from flask import Flask

app = Flask(__name__)


@app.route("/")
def index():
    return "Hello world!"

there is a venv virtual environment under the project folder. Under powershell, start the virtual environment to run the flask program normally. But when I added the python interpreter path corresponding to the virtual environment under the project folder to the workspace settings of visual studio code, visual studio reported an error, and the error reported was a bit strange:

Error: Could not import "D".

the python paths I added in the workspace settings are as follows. I have tried both and reported the above errors:

{
    "python.pythonPath": "${workspaceFolder}/venv/Scripts/python.exe",
    //"python.pythonPath": "D:/_TEMP/venv/Scripts/python.exe",
}

deleting the added python path, visual studio code in the workspace configuration will run the program properly. (because I installed the flask framework under the global path)

question: how do I configure the python path for the virtual environment in visual studio code?


the new version of VS Code automatically detects the Python environment, requiring .env files in the directory, or parsing the environment created by pipenv directly (highly recommended)


has solved this problem, which is the problem of the latest version of flask. See this issue: python/issues/1634" rel=" nofollow noreferrer "> Flask debugger configuration fails (Window) with" could not import "message

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b39b78-2c19a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b39b78-2c19a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?