VS debug di Codice di errore di importazione, mentre tenta di eseguire il debug pallone app

0

Domanda

Io attualmente ho una boccetta di applicazione in cui la struttura dei file simile a questo:

C:\Users\kmelton\Python\Flask\BGSCS-API-dev\InterjectApi\server.py

E la cartella attualmente ho aperto uno spazio di lavoro in VS Codice è il BGSCS-API-dev cartella.

Il mio lancio.json attualmente simile a questo:

{
    // 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: Flask",
            "type": "python",
            "request": "launch",
            "module": "flask",
            "env": {
                "FLASK_APP": "server.py",
                "FLASK_ENV": "development"
            },
            "args": [
                "run",
                "--no-debugger"
            ],
            "jinja": true
        }
    ]
}

E su ogni tentativo di debug, ho un errore.

 * Serving Flask app 'server.py' (lazy loading)
 * Environment: development
 * Debug mode: on
Usage: python -m flask run [OPTIONS]
Try 'python -m flask run --help' for help.

Error: Could not import 'server'.

So che probabilmente c'è qualcosa che devo aggiungere al mio lancio.file json, il percorso per il file correttamente, ma le cose che ho provato non ha funzionato per me. Grazie

1

Migliore risposta

0

Ok, ho risolto l'errore iniziale che ho avuto, solo per essere di fronte a un nuovo errore di pertinenza importare un altro problema, questa volta realmente all'interno del codice, l'importazione di un file che importa fine quando si esegue il programma normalmente.

Il fix l'ho implementato il mio codice è il seguente (in un raggio di lancio.json)

{
    // 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: Flask",
            "type": "python",
            "request": "launch",
            "module": "flask",
            # Added new line cwd to specify initial working directory
            "cwd":"${workspaceRoot}",
            "env": {
                # Added ${workspaceRoot}/InterjectApi/"file name trying to run"}
                "FLASK_APP": "${workspaceRoot}/InterjectApi/server.py",
                "FLASK_ENV": "development"
            },
            "args": [
                "run",
                "--no-debugger"
            ],
            "jinja": true
        }
    ]
}
2021-11-23 18:16:30

In altre lingue

Questa pagina è in altre lingue

Русский
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................