I've just started using VS Code with the Python plugin. I've set up a venv, launched code within that venv, installed all my necessary modules and updated my launch.json to launch flask apps as follows:
{
"name": "Python: Flask (0.11.x or later)",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config:python.pythonPath}",
"program": "${workspaceFolder}/env/Scripts/flask.exe",
"cwd": "${workspaceFolder}",
"env": {
"FLASK_APP": "${workspaceFolder}/main.py"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
],
"envFile": "${workspaceFolder}/.env",
"debugOptions": [
"RedirectOutput"
]
},
However when I launch the debugger for Flask in VS Code the following appears in my debug console:
ValueError: source code string cannot contain null bytes
However, if I just launch the app from the commandline doing:
set FLASK_APP=main.py
python -m flask
it works just fine. I'm sure it's something stupid I've done but I can't figure out what that is.
Note also that pythonPath points to my venv python installation.
"program": "${workspaceFolder}/env/Scripts/flask.exe"Is that right, or should it be a Python script or something?flask.exe? For example, do you have a file calledflask.py? It does seem slightly unlikely to me thatlaunch.jsonwould have a field which can be either a binary or a script.python -m flaskIn either case, though, your app's entry point is defined as an env var, FLASK_APP."program"to the Python script for flask, if you can find it. It must exist somewhere, ifpython -m flaskworks.