VsCode上配置Python

第一步:安装python插件

在这里插入图片描述

第二步:
方法一:(python官方轮子),待会儿需要配置一下,网络常用

或许按这位老师的方法更好,先用pip装倆轮子,查资料说是python官方的,用来检查代码正确性、和格式化代码的,传送门:

用VScode配置Python开发环境

方法二:(vscode自带),包大,检测功能复杂些,不用配置

打开一个.py文件
这里忘记截图了,但是会 自动提示 你安装两个东西:
1、pylint用来检测py代码正确性的,
2、autopep用来格式化代码的
3、但这个是连外网,要花几分钟,按下面老师pip先去清华镜像装再来配置那就更快了。
在这里插入图片描述

再分享一些配置
1、输出平台切换:

visual studio code 输出到“调试控制台”而不是“终端”

用终端输出用调试窗口输出
在这里插入图片描述在这里插入图片描述
2、所需包路径配置

vscode 配置 python3开发环境

3、vscode配置大全①

vscode 基本配置和使用

4、使用python官方的代码格式工具yapf+检测工具flake8

pip安装上述两个轮子后,在settings.json中加入配置。

pip install flake8 -i https://pypi.tuna.tsinghua.edu.cn/simple
"python.linting.flake8Enabled": true,
"python.formatting.provider": "yapf",
"python.linting.flake8Args": ["--max-line-length=130"],
"python.linting.pylintEnabled": false

在这里插入图片描述

5、按ctrl + 空格键调出相关属性菜单,查看launch.json中的所有属性。

在这里插入图片描述

6、关于launch.json、task.json设置的官方文档

https://code.visualstudio.com/docs/editor/debugging#_launch-configurations
https://code.visualstudio.com/docs/editor/variables-reference#_common-questions

6.1、变量引用 -> 预定义变量。

vscode 在 调试、任务配置文件、以及一些选择设置 中 支持 变量引用
变量引用 在 键值对的字符串中受到支持,在 launch.json、tasks.json文件使用${variableName}语法。

The following predefined variables are supported:
Tip:中文解释所指的“文件”是 vscode 中激活的文件

预定义名英文解释中文解释
${workspaceFolder}the path of the folder opened in VS Code根目录绝对路径
${workspaceFolderBasename}the name of the folder opened in VS Code without any slashes (/)根目录的名字
${file}the current opened file文件的绝对路径
${relativeFile}the current opened file relative to workspaceFolder相对于根目录
文件的相对路径
${relativeFileDirname}the current opened file’s dirname relative to workspaceFolder相对于根目录
文件的目录名相对路径
${fileBasename}the current opened file’s basename文件的名称(有后缀
${fileBasenameNoExtension}the current opened file’s basename with no file extension文件的名称(无 后缀 )
${fileDirname}the current opened file’s dirname文件目录名绝对路径
${fileExtname}the current opened file’s extension文件的后缀
${cwd}the task runner’s current working directory on startupvscode 启动时打开的目录
${lineNumber}the current selected line number in the active file在激活的文件中选中的行号
${selectedText}the current selected text in the active file在激活的文件中选中的文本
${execPath}the path to the running VS Code executable运行 vscode 可执行代码的路径
${defaultBuildTask}the name of the default build task默认生成任务的名称(这个不知咋用)

如果看不懂这个解释,使用下面这个方法查看真实值是什么

6.2、查看${workspaceFolder}具体是什么值的方法。在这里插入图片描述

在你的task.json中将按上图设置,在Terminal菜单中Run Task

在这里插入图片描述

6.3 vscode 自定义配色方案

VSCode自定义配色方案

6.4 vscode配置topper

参考了上面一篇文章。我也进行了我的配置,注释掉了一些,然后也改了下python的。
在这里插入图片描述
这一块就可以自动插入了。
在这里插入图片描述
放上我的topper配置代码,就复制到settings.json里面的第一层大括号里面就好了。

// 下面是topper的插入header配置
    "topper.customTemplateParameters": [
        {
            "personalProfile": {
                "author": "harry",
                // "website": "bulbasaur.github.bitbucket.yababbdadado.com",
                // "copyright": "None \n None",
                // "license": "None",
                "email": "619342297@qq.com",
                "description": "do somethings"
            }
        }
    ],
    "topper.headerTemplates": [
        {
            "defaultCStyled": {
                "headerBegin": "/**",
                "headerPrefix": "*",
                "headerEnd": "*/",
                "template": [
                    "${headerBegin}",
                    // "${headerPrefix} ${fileName}",
                    "${headerPrefix} author: ${author}",
                    "${headerPrefix} description: ${description}",
                    "${headerPrefix} created: ${createdDate}",
                    "${headerPrefix} copyright: ${copyright}",
                    "${headerPrefix} last-modified: ${lastModifiedDate}",
                    // "${headerEnd}"
                ]
            }
        },
        {
            "python": {
                "template": [
                    "# -*- coding: utf-8 -*-",
                    "'''",
                    "author: ${author}",
                    "description: ${description}",
                    "created: ${createdDate}",
                    "last-modified: ${lastModifiedDate}",
                    "'''"
                ]
            }
        }
    ],
设置yapf格式化工具

很多时候漏掉这一句:则yapf就无效了:
报错:python语言基础功能 无法格式化
在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值