VSCode用Run code插件配置python环境(win10)


一、下载python编译器(一个就够了)

要么去python官网下python,要么去anaconda官网下python。

1.python官网

  1. https://www.python.org/downloads/windows/
  2. 选择x64的可执行文件
    在这里插入图片描述
  3. 勾选环境变量
    在这里插入图片描述
  4. 自定义安装位置
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

PS:不要直接下载,直接下载下来的是32位的。
在这里插入图片描述

2.Anaconda

  1. https://www.anaconda.com/distribution/#download-section

  2. 选择64位安装
    在这里插入图片描述

  3. 之后安装就好了。

二、VSCode配置

1.插件

  1. 安装Code Runner插件
    在这里插入图片描述
    然后你会发现多了个.vscode配置文件夹,里面有setting.json文件。这些意思就是刚才勾选的东西。
    在这里插入图片描述

  2. 同理,安装Python插件
    在这里插入图片描述

2.配置Run code

(1)图形化配置

  1. 其实我们在(一)下载Python环境要的就是python.exe可执行文件(一个就够了)。
  • python文件夹下的
    在这里插入图片描述
  • anaconda文件夹下的
    在这里插入图片描述
  1. 在菜单中,文件→首选项→设置。在"搜素设置"中输入python.PythonPath,在检索出的设置中输入你刚刚下好的python.exe的路径。
    在这里插入图片描述
    在这里插入图片描述
  2. ctrl+s保存,然后再关闭。然后你会发现.vscode配置文件夹中的setting.json文件更新了。多的东西就是你的刚才更改的。
    在这里插入图片描述
  3. python.exe和Run code插件联系起来。编辑setting.json,加入"code-runner.executorMap"部分。
{
    "code-runner.runInTerminal": true,
    "code-runner.saveFileBeforeRun": true,
    "python.pythonPath": "D:\\Python\\python.exe",
    "code-runner.executorMap": {
    	// 加上-u(unbuffered)参数后会强制其标准输出也同标准错误一样不通过缓存直接打印到屏幕
        "python":"python -u $fullFileName"
    }
}

(2)setting.json

{
    // 解决终端中文乱码
    "terminal.integrated.shellArgs.windows": ["-NoExit", "/c", "chcp 65001"],
    "terminal.integrated.fontFamily": "Lucida Console",
    // code-runner插件运行在终端上
    "code-runner.runInTerminal": true,
    // code-runner插件点击运行自动保存文件
    "code-runner.saveFileBeforeRun": true,
    // python配置,python.exe编译器的位置
    "python.pythonPath": "D:\\Python\\python.exe",
    // 配置python插件执行的命令:用上面python.exe编译器,编译要执行的文件
    "code-runner.executorMap": {
    	// 加上-u(unbuffered)参数后会强制其标准输出也同标准错误一样不通过缓存直接打印到屏幕
        "python":"python -u $fullFileName"
    },
}

三、运行

  1. 新建个python文件
    在这里插入图片描述
  2. ctrl+alt+n运行run code插件
    在这里插入图片描述

Reference

使用vscode打造python开发环境

发布了486 篇原创文章 · 获赞 204 · 访问量 13万+

猜你喜欢

转载自blog.csdn.net/sandalphon4869/article/details/105456755