在VSCode中配置Python运行环境

很多时候只需要写一些小脚本,就十几二十行的样子,打开PyCharm什么的太费劲了,可以考虑用VSCode便捷开发。

在VSCode中只需要配置好launch,json就可以按F5进行调试了。
打开launch.json:调试 >> 打开配置
修改 pythonpath 词条:

"version": "0.2.0",
    "configurations": [
        {
            "name": "Python",
            "type": "python",
            "request": "launch",
            "stopOnEntry": false,
            "pythonPath": "C:/Python27/python",//改成自己的路径
            "program": "${file}",
            "cwd": "${workspaceRoot}",
            "env": {},
            "envFile": "${workspaceRoot}/.env",
            "debugOptions": [
                "WaitOnAbnormalExit",
                "WaitOnNormalExit",
                "RedirectOutput"
            ]
        },

在第一次写Python程序的时候如果没有注意是python2.x还是python3.x还会遇见一些小问题,如:

print‘hello world’ 
出现错误SyntaxError: Missing parentheses in call to ‘print’ 
后改成print(‘hello world’)可正确输出

python从3.0后将print变为一个函数,所以需要加上括号。类似的还有:
NameError: name ‘raw_input’ is not defined
3.0以后把raw_input变成了input。

猜你喜欢

转载自blog.csdn.net/qq_28301007/article/details/80449490