美文网首页
Vscode 配置为Python IDE

Vscode 配置为Python IDE

作者: testerH2o | 来源:发表于2020-03-20 16:54 被阅读0次

1.文件头添加

  • 自定义代码片段
  1. 文件>首选项>用户代码片段
  2. 搜索python
  3. 添加代码
"HEADER":{
        "prefix": "header",
        "body": [
            "# -*- encoding: utf-8 -*-",
            "",
            "# @File    : $TM_FILENAME",
            "# @Time    : $CURRENT_YEAR/$CURRENT_MONTH/$CURRENT_DATE $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND",
            "# @Author  : testerH2o ",
            "# @Version : 1.0",
            "# @Contact : 515430193@qq.com",
            "",
            "",
            ""
        ],
    }
  • 添加文件头
  1. 新建文件
  2. 输入header
  3. 选择header

2.进入设置界面

  1. 在vscode中打开一个文件
  2. 点击左下角"齿轮"图标
  3. 选中设置

3.为不同的项目配置python虚拟环境

  1. 设置界面, 切换tab到工作区
  2. 设置搜索框输入:python.pythonPath
  3. 将新建的虚拟环境地址添加即可, 如: D:\ENV\Testtools\Scripts\python.exe

4.自动函数生成注释模板

  1. 下载插件: autoDocstring
  2. 快捷键: ctrl+shift+2, 或在函数定义后输入: """

  4.1.切换注释生成模板

  1. 设置界面, 搜索autoDocstring
  2. 修改autoDocstring.docstringFormat栏即可

  4.2.自定义注释模板样式

  1. 新建.mustache文件
  2. 修改autoDocstring.docstringFormat栏为default
  3. 修改autoDocstring.customTemplatePath为你新建的.mustache文件的地址

(详细关键字配置请查看插件介绍)

个人使用google注释模板,.mustache文件内容如下:

{{! Google Docstring Template }}
{{summaryPlaceholder}}
{{extendedSummaryPlaceholder}}
{{#parametersExist}}
Args:
{{#args}}
    {{var}} ({{typePlaceholder}}): {{descriptionPlaceholder}}
{{/args}}
{{#kwargs}}
    {{var}} ({{typePlaceholder}}, optional): {{descriptionPlaceholder}}. Defaults to {{&default}}.
{{/kwargs}}
{{/parametersExist}}

{{#exceptionsExist}}
Raises:
{{#exceptions}}
    {{type}}: {{descriptionPlaceholder}}
{{/exceptions}}
{{/exceptionsExist}}

{{#returnsExist}}
Returns:
{{#returns}}
    {{typePlaceholder}}: {{descriptionPlaceholder}}
{{/returns}}
{{/returnsExist}}

5.配置代码格式化工具

(以black为例)

  1. pip install black
  2. 设置界面, 搜索python.formatting.provider, 选择black
  3. 设置界面, 搜索python.formatting.blackPath, 输入你的black安装路径
    例如: C:\Program Files\Python36\Scripts\black.exe
  4. (选配)配置black运行参数, 设置界面, 搜索python.formatting.blackArgs, 添加: --line-length=80

    (black每行允许的字符长度为88)

6.配置代码静态检查工具

(以pylint为例)

  1. pip install pylint (若是虚拟环境, 建议切换到虚拟环境后, 再pip安装)
  2. 设置界面, 搜索python.linting.pylintPath, 输入你的pylint安装的路径
  3. 设置界面, 搜索python.linting.enabled, 选中即可
  4. 设置界面, 搜索python.linting.pylintEnabled, 选中即可

7.插件安装

项目 说明 是否必需安装
Python
vscode-icons 美化文件图标
Better Comments 美化行注释
Chinese (Simplified) Language Pack
for Visual Studio Code
中文汉化包
autoDocstring 函数注释模板生成

8.我的配置

  8.1 用户json

{
    "files.autoSave": "afterDelay",
    "editor.renderWhitespace": "all",
    "editor.wordWrap": "wordWrapColumn",
    "workbench.startupEditor": "newUntitledFile",
    "workbench.iconTheme": "vscode-icons",
    "workbench.colorTheme": "Bluloco Light",
    "editor.fontFamily": "InputMono, Consolas, 'Courier New', monospace",
    "editor.fontSize": 15,
    "editor.lineHeight": 27,
    "python.formatting.provider": "black",
    "python.formatting.blackPath": "C:\\Program Files\\Python36\\Scripts\\black.exe",
    "python.formatting.blackArgs": [
        "--line-length=80"
    ],
    "editor.renderControlCharacters": false,
    "autoDocstring.customTemplatePath": "C:\\Program Files\\Microsoft VS Code\\data\\google.mustache"
}

  8.2 工作区json

{
    "python.pythonPath": "D:\\ENV\\Testtools\\Scripts\\python.exe",
    "python.linting.pylintEnabled": true,
    "python.linting.enabled": true,
}

相关文章

  • pytest的使用

    1、Python+VSCode IDE 快速开发配置 来源:Python+VSCode IDE 快速开发配置-16...

  • Vscode 配置为Python IDE

    1.文件头添加 自定义代码片段 文件>首选项>用户代码片段 搜索python 添加代码 添加文件头 新建文件 输入...

  • 应用python轻松excel自动化00

    开发环境配置-VScode 用VScode配置Python开发环境[https://www.jianshu.com...

  • Python学习

    一. Python配置 这里学习python,我们使用的是VSCode,首先在VSCode中安装Python插件,...

  • python 相关

    vscode 配置 python User Settings 里配置使用 python3 配置 flake8 安装...

  • 在VScode上配置Git

    前言 在上一篇文章《用VScode配置Python开发环境》中,我们讲了怎么在VScode上配置python开发环...

  • 爬虫环境的配置

    IDE的安装 IDE我用的是VS code,也用过pycharm(但是电脑配置不行,比较卡) VScode安装教程...

  • 【Python 1-2】Visual Studio Code(V

    使用 VSCode 作为开发Python的IDE工具 文章首发地址[http://fulade.me/2020/1...

  • Python入门系列文章

    Sublime Text3 配置成Python IDE环境 Python Flask RESTful API --...

  • Scrapy学习——环境搭建

    本项目使用mac开发,环境配置都是基于mac的环境,python版本为2.7,IDE为PyCharm,数据库为my...

网友评论

      本文标题:Vscode 配置为Python IDE

      本文链接:https://www.haomeiwen.com/subject/fyojyhtx.html