最近我遇到了这个问题,我会打开一个以前运行良好的 .py 文件,我会单击运行代码,但什么也不会发生。 当我打开包含该文件的文件夹并运行代码时,python 终端运行良好,没有任何问题,因此如果不打开文件夹,我根本无法在 VScode 中运行 python 终端。
我搜索了很多,发现的只是卸载并重新安装并删除 .vscode 文件夹(干净重新安装)。
重新安装后,是的,它运行正常,但如果我打开一个文件夹,关闭它并尝试打开一个文件,它根本不会再次运行 python 终端。
不断尝试询问,解决办法是关闭工作区:文件>关闭工作区。 非常简单的解决方案,我不知道它,因为我是初学者,我想把它留在某个地方,这样就不会有人像我一样花费时间沮丧并不得不重新安装 VScode 多次,初学者问题哈哈。
简化一下: 尝试运行 python 文件,python 终端根本不运行。 解决方案是关闭工作空间,文件 > 关闭工作空间。
vscode
文件夹中有一个 launch.json
文件,该文件告诉它当您单击 run
或按 F5
时如何表现。
我通常将我的内容设置为:
{
// 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": [
// nodes
{
"type": "node",
"request": "launch",
"name": "node: Launch Program",
"program": "${file}",
"console": "integratedTerminal"
},
{
"type": "node",
"request": "launch",
"name": "node: Launch Program (External Terminal)",
"program": "${file}",
"console": "externalTerminal"
},
// pythons
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
},
{
"name": "Python: Current File (External Terminal)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "externalTerminal"
}
]
}
文件夹和子文件夹中的所有内容都将按预期工作。
你可以在这里看到我的 python 配置(你可能只需要
integratedTerminal
一个)。我还有一些你可以使用的 Nodejs 配置设置。
我写这个答案的原因是每当设置新环境时我总是遇到类似的问题。