在Mac OS X上使用Python3使用Visual Studio代码 - 无法正常工作

时间:2017-06-05 04:41:49

标签: python json macos python-3.x visual-studio-code

我无法让Python3在调试时继续使用Python2。我尝试了一些东西,但仍然无法让它发挥作用。我验证了Python3s的路径是/ usr / local / bin / python3 每次我通过

运行脚本
import sys
print(sys.version)

我仍然得到2.7.10 python 3已安装并正常工作。

我在我的launch.json和settings.json中有这个(在launch.json中由于某种原因,类型和请求都显示为灰色)

 {
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"program": "${file}",
"pythonPath": "/usr/local/bin/python3",
"debugOptions": [
    "WaitOnAbnormalExit",
    "WaitOnNormalExit",
    "RedirectOutput"
] }

4 个答案:

答案 0 :(得分:1)

要选择特定的python解释器,请从命令面板(⇧⌘P)中调用 Python:选择解释器命令。

enter image description here

这将更新您的 .vscode / settings.json 文件:

{
    "python.pythonPath": "/usr/local/bin/python3"
}

然后您应该能够使用python 3解释器进行调试,或者您的计算机上提供了其他任何python解释器。

答案 1 :(得分:0)

This is not an answer, but my rep won't allow a comment: For me your proposed solution worked just fine. Here some troubleshooting:

  • Did you change the original launch.json entry? Then you probably need to reload it, which should happen automatically, but restarting VSCode will do that for sure.
  • Also, I would recommend using the "Add Configuration" button, then choose "python", and edit the name in the new entry (from "Python" to "Python3") as not to clash with the old python entry, as well as change the "pythonPath" key's value from "${config:python.pythonPath}" to "/usr/local/bin/python3"

To use this config, select in the Debug dropdown box.

答案 2 :(得分:0)

如果您使用“code runner”,则可以尝试使用命令调色板打开用户设置。

{
    "code-runner.executorMap": {
        "python": "python3"
    }
}

这对我有用。

答案 3 :(得分:0)

对我有用的是将以下内容添加到用户设置:

{
    "python.pythonPath": "/usr/local/bin/python3"
}