thisguy
thisguy

Reputation: 57

Unable to debug Flask app in Visual Studio Code

I have a currently working flask app. I want to debug it in Visual Studio Code. I keep hitting errors that I can't google my way out of. I have gone through How do I debug Flask App in VS Code and the video, it did not solve my inability to debug. I have also copied the instructions from https://code.visualstudio.com/docs/python/tutorial-flask and I was able to debug in a new example file! But I can't translate this success to my current project that I cannot debug. The main error line seems to be ModuleNotFoundError: No module named 'app'. Or perhaps that isn't the error, I can't tell. If any further information is needed please state so, I don't want to plaster endless error messages.

Also my launch.json is correctly copied/formatted based off both the visual studio code tutorial and from Miguel's(the first link). The end goal is to step through the visual studio code debugger successfully.

C:\Users\OMITTED\Documents\project>cmd /C "set "PTVSD_SESSION_ID=1" && set "PTVSD_LAUNCHER_PORT=59672" && C:\Users\OMITTED\AppData\Local\Programs\Python\Python37\python.exe c:\Users\OMITTED\.vscode\extensions\ms-python.python-2019.11.50794\pythonFiles\lib\python\new_ptvsd\wheels\ptvsd\launcher -m flask "
Traceback (most recent call last):
  File "C:\Users\OMITTED\AppData\Local\Programs\Python\Python37\lib\site-packages\flask\cli.py", line 240, in locate_app
    __import__(module_name)
ModuleNotFoundError: No module named 'app'

Continued ->

Traceback (most recent call last):
  File "C:\Users\OMITTED\AppData\Local\Programs\Python\Python37\lib\site-packages\flask\cli.py", line 556, in list_commands
    rv.update(info.load_app().cli.list_commands(ctx))
  File "C:\Users\OMITTED\AppData\Local\Programs\Python\Python37\lib\site-packages\flask\cli.py", line 388, in load_app
    app = locate_app(self, import_name, name)
  File "C:\Users\OMITTED\AppData\Local\Programs\Python\Python37\lib\site-packages\flask\cli.py", line 250, in locate_app
    raise NoAppException('Could not import "{name}".'.format(name=module_name))
flask.cli.NoAppException: Could not import "app".
Usage: python -m flask [OPTIONS] COMMAND [ARGS]...

Project Structure

Upvotes: 1

Views: 1896

Answers (1)

thisguy
thisguy

Reputation: 57

I changed my "env":{"FLASK_APP"= LOCATION}

LOCATION is the entire source path to your root app.py.

AKA C:\Users\Folder\Folder\app.py but use \\ instead of \ when answering in code.

Upvotes: 2

Related Questions