我在macOS Sierra(10.12.6)上运行VS Code 1.33.1。当我运行如下的简单Python程序时,VS Code使用安装在我的Mac上的Python 2.7,而不是使用Homebrew安装的Python 3。
# show-python-version.py
import sys
print(sys.version)
这是VS Code Output窗口中显示的输出:
[Running] python -u "/Users/smith/Documents/Programming/Python/Examples/show-python-version.py"
2.7.15 (default, May 1 2018, 16:44:37)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]
[Done] exited with code=0 in 0.032 seconds
正如你所看到的,我得到版本2.7.15,因为它调用“python”而不是“python3”,但我不知道如何使用python3。以下是我为解决此问题所做的所有事情:
{
"python.pythonPath": "/usr/local/bin/python3"
}
我安装了这些扩展程序:
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
它可能与我的路径有关,如下所示,因为python和python3都在/ usr / local / bin中:
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:....
我究竟做错了什么?
这是因为代码运行器扩展将这个"code-runner.executorMap.python": "python3 -u"
添加到您的settings.json,这应该更改python版本,因为它运行代码到python3而不是python2