You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS Code中Flask配置在Windows下引发“无法导入模块”提示问题

Flask应用在Windows VS Code启动器运行时出现"Unable to find python module."提示问题

我有一个Flask应用,在macOS和Windows系统均可正常运行,但在Windows系统的VS Code终端通过启动器运行时,会弹出多条**"Unable to find python module."**提示(应用本身仍能正常运行),怀疑是VS Code配置存在问题。

说明:/Website是VS Code项目的子文件夹,项目根目录在上一级,launch.json中配置了cwd参数,该参数在macOS下正常工作,可能与Windows下的问题相关。


相关信息

1. Windows命令行直接运行的终端输出(运行正常)

(.venv) PS C:\Users\Brett\Documents\Development\Project\Website> flask run
Running in production mode
 * Debug mode: off
2023-10-14 12:37:17,733 INFO WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on http://127.0.0.1:5000 [_internal.py:_internal:_log:96]
2023-10-14 12:37:17,734 INFO Press CTRL+C to quit [_internal.py:_internal:_log:96]
(.venv) PS C:\Users\Brett\Documents\Development\Project\Website>

2. 通过VS Code启动器运行的终端输出(出现提示)

(.venv) PS C:\Users\Brett\Documents\Development\Project\Website>  C:; cd 'C:\Users\Brett\Documents\Development\Project/Website'; & 'c:\Users\Brett\Documents\Development\Project\Website\.venv\bin\python3.exe' 'c:\Users\Brett\.vscode\extensions\ms-python.python-2023.18.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '58689' '--' '-m' 'flask' 'run' '--no-debugger' '--no-reload'
Unable to find python module.
Unable to find python module.
Unable to find python module.
Unable to find python module.
Unable to find python module.
Unable to find python module.
Unable to find python module.
Running in debug mode
2023-10-14 12:37:35,973 INFO Logging setup complete [__init__.py:__init__:init_app:62]
 * Serving Flask app 'wsgi.py'
 * Debug mode: on
2023-10-14 12:37:36,002 INFO WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on http://127.0.0.1:5000 [_internal.py:_internal:_log:96]
2023-10-14 12:37:36,002 INFO Press CTRL+C to quit [_internal.py:_internal:_log:96]
(.venv) PS C:\Users\Brett\Documents\Development\Project\Website>

3. VS Code的launch.json配置

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Flask",
            "type": "python",
            "cwd": "${workspaceFolder}/Website",
            "request": "launch",
            "module": "flask",
            "env": {
                "FLASK_APP": "wsgi.py",
                "FLASK_DEBUG": "1"
            },
            "args": [
                "run",
                "--no-debugger",
                "--no-reload"
            ],
            "jinja": true,
            "justMyCode": true
        },
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true
        }
    ]
}

4. wsgi.py代码(提示在断点触发前出现)

from application import init_app

app = init_app()

if __name__ == "__main__":
    app.run(host='0.0.0.0')

内容的提问来源于stack exchange,提问作者mr.b

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 22:30:17