VSCode中配置Python环境时出现“调试中的Python路径设置无效”
问题现象:VScode提示“调试中的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。