栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

VScode提示“调试中的Python路径设置无效” 的解决方案

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

VScode提示“调试中的Python路径设置无效” 的解决方案

VSCode中配置Python环境时出现“调试中的Python路径设置无效”
  • 问题现象:VScode提示“调试中的Python路径设置无效”
  • 解决方法

问题现象:VScode提示“调试中的Python路径设置无效”

现象如图所示:

图1:调试中的Python路径设置无效
在这里插入图片描述

解决方法

根据网上的很多方法,都试过,但是都不行,但是又不愿意重装,但是实际解决该问题比较简单。
1.在注册表中添加对应的路径,比如我的路径添加情况如如下:

  • Administrator 用户环境变量添加了(根据你的Python安装路径添加)
    C:UsersAdminstratorAppDataLocalProgramsPythonPython39
    C:UsersAdminstratorAppDataLocalProgramsPythonPython39Scripts
  • 全局用户环境变量添加了(根据你的Python安装路径添加)
    C:UsersAdminstratorAppDataLocalProgramsPythonPython39
    C:UsersAdminstratorAppDataLocalProgramsPythonPython39Scripts
    2.在VSCode的Python插件中将默认路径修改(路径包含python.exe):

    3.在VSCode的工程中的launch.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 当前文件",
            "type": "python",
            "request": "launch",
            "stopOnEntry": false,
            "pythonPath": "C:\Users\Adminstrator\AppData\Local\Programs\Python\Python39\python.exe",
            "program": "${file}",
            "cwd": "${workspaceRoot}",
            "env": {},
            "envFile": "${workspaceRoot}/.env",
            "console": "integratedTerminal"
        }
    ]
}

这里比较重要的是

 "pythonPath": "C:\Users\Adminstrator\AppData\Local\Programs\Python\Python39\python.exe",

这个路径必须指定到python.exe 这一级,并且目录间隔要使用双斜线""来分割。
然后就可以解决问题了,也不需要重装VScode 和Python。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/833898.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号