jmh*_*jmh 4 python visual-studio-code
我正在尝试使用 VScode 来运行一些使用 python 2.7.13 的脚本,但它似乎总是使用 python 3。首先我设置了 2 个虚拟环境。一种用于 python 2,一种用于 python 3。这似乎不会影响 VSCode。它似乎总是使用 python 3。我知道它使用 python 3,因为我在代码中添加了以下两行:
aa=10
print aa
Run Code Online (Sandbox Code Playgroud)
但我总是收到与打印语句相关的错误消息。我知道如果我在打印语句中使用括号一切正常。
我还尝试从 VSCode 的命令面板中使用“Python:选择解释器”。这也行不通。
我在带有 High Sierra 的 Mac 上运行。我有最新版本的 VScode,1.23。
做错了什么?如何让 VScode 使用 python 2。
小智 2
首先,在vscode的终端中:
suyichengdeMacBook-Air:alltest suyicheng$ python -V
Python 2.7.10
suyichengdeMacBook-Air:alltest suyicheng$ python3 -V
Python 3.6.2
Run Code Online (Sandbox Code Playgroud)
在我的 vscode 中,我可以使用 python 或 python3,也许在你的计算机中,它将是 python2.7 或其他。
然后,设置,搜索“python.pythonPath”。
如果我想使用python3.X,我设置
"python.pythonPath": "python3"
Run Code Online (Sandbox Code Playgroud)
然后:
File "/Users/suyicheng/bs/alltest/test.py", line 2
print 22
^
SyntaxError: Missing parentheses in call to 'print'
Run Code Online (Sandbox Code Playgroud)
当我设置时:
"python.pythonPath": "python",
Run Code Online (Sandbox Code Playgroud)
可以用啦~
希望我蹩脚的英语能帮到你~