1

I have my Flask installed in my main directory for playing with Flask projects and I don't want to change it (its name is tryFlask). My project is in one of the subdirectories to tryFlask (main_project). How should I config my launch.json so that it doesn't throw errors when I try to debug?

Current config which throws:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Flask",
            "type": "python",
            "request": "launch",
            "module": "flask",
            "env": {
                "FLASK_APP": "my_app.py",
                "FLASK_ENV": "tryFlask",
                "FLASK_DEBUG": "1"
            },
            "args": [
                "run",
                "--no-debugger",
                "--no-reload"
            ],
            "jinja": true,
            "justMyCode": true
        }
    ]
}

And yes I have already checked "FLASK_APP": "my_project/my_app.py". Doesn't work. Neither does reinstalling dependencies or even choosing different interpreters from venv's bin subdirectory.

4
  • No matter where you installed flask, just choose the interpreter for the python environment where flask is installed. Commented Oct 18, 2022 at 5:45
  • Yes I chose it from the venv's bin directory, @JialeDu, but I have shortcuts to interpreters. I even swapped them. Still throws error Commented Oct 18, 2022 at 5:48
  • Can you show how you choose? Provide more details. Commented Oct 18, 2022 at 6:01
  • cmd + shift + P (I'm working on Mac) -> Python: Select Interpreter -> Choose path -> Find -> tryFlask -> bin -> shortcut to Python3 or Python3.10; Neither works, @JialeDu. I also tried my main Python 3.10 that was in suggested interpreters Commented Oct 18, 2022 at 6:07

1 Answer 1

1

If you want to use flask with vscode, following this tutorial is a good start.

According to the question in your post, if you want to specify the python interpreter when debugging, you can add the python configuration to launch.json

Simple example:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true,
            // Modify the python interpreter with flask installed on your machine
            "python": "C:\\WorkSpace\\pytest10\\.venv\\Scripts\\python.exe"
            // "python": "${workspaceFolder}/.venv/Scripts/python.exe"

        }
    ]
}

enter image description here

For more launch.json configuration, you can check this link.

Sign up to request clarification or add additional context in comments.

7 Comments

You should use ${workspaceFolder}, ideally
Could you provide more detail about where and which key to put? Preferably an article / tutorial where you have found this answer, @JialeDu
I updated the answer, feel free to let me know if you have any questions.
I used my main Python path on MacOS: "/Library/Frameworks/Python.framework/Versions/3.10/bin/python3" And I got: SyntaxError: invalid syntax on this very line of code, @JialeDu. And yes I strated with this tutorial, but couldn't get the app to run in the VSCode terminal so skipped this part - choosing different interpreters, neither worked. I don't have Scripts directory in my venv and still Flask is working well.
I'm sorry I don't have a mac to reproduce your problem. One other suggestion is to use the code in the picture in my answer to get the full path to the current interpreter, then path -m pip install flask install flask.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.