解决:我忘记更新程序密钥以始终指向main.py,因此我的配置将当前打开的文件作为Python脚本运行.正确设置程序密钥或导航到不同的文件是解决方案.当StackOverflow允许我时,我会将我的答案标记为解决方案.
我正在尝试从Visual Studio代码运行Python脚本,但是脚本无法运行并且因为指向launch.json开头的注释的SyntaxError而崩溃.
launch.json:
<code>{
// 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 | Default",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config:python.pythonPath}",
"program": "${file}",
"cwd": "${workspaceFolder}",
"env": {},
"envFile": "${workspaceFolder}/.env",
"debugOptions": [
"RedirectOutput"
]
}
]
}
</code>
终端输出:
<code>File ".../.vscode/launch.json", line 2
// Use IntelliSense to learn about possible attributes.
^
SyntaxError: invalid syntax
</code>
settings.json:
<code>{
"python.pythonPath": "${workspaceFolder}/venv/bin/python"
</code>
}
我之前在我的Windows机器上工作,所有这一切都很好.出于某种原因,VSCode试图通过Python运行launch.json文件,而//是Python中的无效注释语法.如果我删除评论,我会收到此错误:
<code>Traceback (most recent call last):
File ".../.vscode/launch.json", line 8, in <module>
"stopOnEntry": false,
NameError: name 'false' is not defined
</code>
如果我使用Python的False,我不会崩溃,但没有任何反应,我的脚本不会运行.看起来非常像launch.json错误地被Python解析.对此有任何修复?
解决方法:
我发现了我的问题.我没有更新程序密钥以始终指向我的main.py.相反,当前打开的文件作为Python脚本执行 – launch.json更改程序密钥或导航到另一个文件解决了问题.一旦你注意到它就显而易见了!
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!