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

VSCode中配置Python环境时出现“调试中的Python路径设置无效”

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

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

解决方法

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

  • Administrator 用户环境变量添加了(根据你的Python安装路径添加)
    C:\Users\Adminstrator\AppData\Local\Programs\Python\Python39
    C:\Users\Adminstrator\AppData\Local\Programs\Python\Python39\Scripts
  • 全局用户环境变量添加了(根据你的Python安装路径添加)
    C:\Users\Adminstrator\AppData\Local\Programs\Python\Python39
    C:\Users\Adminstrator\AppData\Local\Programs\Python\Python39\Scripts
    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。

  • 6
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值