VS Depurador de Código de error de importación, mientras que tratando de depurar el matraz de aplicación

0

Pregunta

Actualmente tengo un frasco de aplicación en la que la estructura de archivos se parece a esto:

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

Y la carpeta en la que tengo actualmente abierto como un área de trabajo en el VS de Código es el BGSCS-API-dev carpeta.

Mi lanzamiento.json en la actualidad se parece a esto:

{
    // 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
        }
    ]
}

Y sobre todo la depuración intento, me sale un error.

 * 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'.

Sé que probablemente hay algo que debo agregar a mi lanzamiento.archivo json a la ruta de acceso al archivo correctamente, pero las cosas que he intentado no ha funcionado para mí. Gracias

1

Mejor respuesta

0

Bueno, así que he resuelto el error inicial que estaba teniendo, sólo para ser enfrentado con un nuevo error perteneciente a otra importar problema, esta vez, de hecho, dentro del código, la importación de un archivo que se importa bien cuando se ejecuta el programa normalmente.

La solución que he implementado para mi código es el siguiente (dentro de lanzamiento.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

En otros idiomas

Esta página está en otros idiomas

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