VSCode,配置python环境

下载VSCode,打开浏览器输入

https://code.visualstudio.com

下载安装

vscode搭建python环境

  (1)安装好vscode后,打开,Ctrl+Shift+x进行扩展程序的安装,搜索python,点击第一个进行安装。(我的已经经过汉化,汉化过程在下面插件中有介绍)

VSCode,配置python环境

 

   (2)然后新建一个文件,这个文件就是你现在的工作空间。

VSCode,配置python环境

 

   创建好之后会变成大写,如下所示:

VSCode,配置python环境

  (3)点击左下角齿轮图标 选择设置,点击工作区,点击右上角使用json设置。

VSCode,配置python环境

 

   点击后是这样的,新配置的vscode可能setting.json是空的。将以下代码复制进去,这些使用来配置yapf的

VSCode,配置python环境

VSCode,配置python环境

{
    "python.linting.flake8Enabled": true,
    "python.formatting.provider": "yapf",
    "python.linting.flake8Args": ["--max-line-length=248"],
    "python.linting.pylintEnabled": false
}

VSCode,配置python环境

  (4)然后点击左边第四个图标,打开launch.json,添加配置,框中的是你python安装的绝对路径

VSCode,配置python环境

VSCode,配置python环境

{
    // 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": [
        {
            "name": "Python",
            "type": "python",
            "request": "launch",
            "stopOnEntry": false,
            "pythonPath": "E:\\Python\\Python38",
            "program": "${file}",
            "cwd": "${workspaceRoot}",
            "env": {},
            "envFile": "${workspaceRoot}/.env"
        }
    ]
}

VSCode,配置python环境

  (5)新建一个.py文件,写上 

print("Hello Python")

  点击右上方的播放箭头,或者连续按两次F5 ,运行程序结果如下,说明搭建成功。

VSCode,配置python环境

VSCode,配置python环境