• Python之VScode基本开发环境


    Python之VScode基本开发环境

    Author:Onceday date:2022年8月10日

    1.引言

    Windows安装Python可参考以下文章:Python安装 Onceday CSDN博客

    Linux平台自带Python,可能需要对pip进行换源:

    1.临时下载某个软件

    pip install markdown -i https://pypi.tuna.tsinghua.edu.cn/simple
    
    • 1

    2.暂时换源

    pip install scrapy -i https://pypi.Python.org/simple/
    
    • 1

    3.永久换源

    # 清华源
    pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
    # 阿里源
    pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
    # 腾讯源
    pip config set global.index-url http://mirrors.cloud.tencent.com/pypi/simple
    # 豆瓣源
    pip config set global.index-url http://pypi.douban.com/simple/
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    联机安装vscode比较容易,离线安装可参考以下文章:离线安装vscode Onceday CSDN博客

    2.安装三款静态检查工具和代码格式化工具

    注意,如果加上sudo前缀安装,则会造成python的包环境污染。

    这里默认给所用用户安装,因此需要root权限操作:

    sudo pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
    
    • 1

    代码格式和语法检查flake8

    sudo pip install flake8
    
    • 1

    依赖包:flake8、pycodestyle<2.10.0,>=2.9.0、pyflakes<2.6.0,>=2.5.0、mccabe<0.8.0,>=0.7.0

    代码格式化工具yapf:

    sudo pip install yapf
    
    • 1

    代码格式和语法检查pylint:

    sudo pip install pylint
    
    • 1

    安装在用户目录下可能bin目录不在PATH环境变量里面,因此要使用绝对路径。

    3.配置vscode的setting文件

        "python.linting.enabled": true,  //开启静态检查
        "python.linting.pylintEnabled": true, //开启pylint静态检查
        "python.linting.flake8Enabled": true, //开启flake8静态检查
        "python.linting.lintOnSave": true,    //保存python文件时自动静态检查
        "python.linting.pycodestyleEnabled": false,  
        "python.linting.pylintArgs": [
            "--max-line-length=100",   //pylint 一行最多100个字符
            "--disable=W0613",
        ],
        "python.linting.flake8Args": [
            "--max-line-length=100",   //flake8 一行最多100个字符
            "--ignore=E501, E262, W191, E266, W504", //忽略相应的错误告警
        ],
        "python.formatting.provider":"yapf",       //格式化工具设置yapf 
        "python.formatting.yapfArgs": ["--style={based_on_style: yapf, indent_width: 4,column_limit=100}"],    
        "python.linting.maxNumberOfProblems": 3000,   //最大检查问题数
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    换行的宽度可根据实际要求来确定。

    另外vscode的编辑器也可使用以下参数限制格式:

    • tab替换为4个空格:Editor:Tab Size
    • 自动保存:Files:Auto Save
    • 自动换行:Editor:Word Wrap,Editor:Word Wrap Column
    • 自动去除尾部空白字符:Files:Trim Trailing Whitespace
    • 换行采用\n形式:File:Eol
    • 默认字符编码UTF-8:File:Encoding

    4.使用额外拼写检查插件

    Code Spell Checker 可以检查常见语言的拼写错误

  • 相关阅读:
    爱上开源之golang入门至实战第四章函数(Func)(七)
    【ElasticSearch】基于 Java 客户端 RestClient 实现对 ElasticSearch 索引库、文档的增删改查操作,以及文档的批量导入
    gis:读取shp文件
    KunlunBase 1.0 发布了!
    一步教你怎么使用Vuex
    Spark 中的分桶分化
    Linux的 一些常见指令
    SpringCloud-MQ消息队列
    【数据结构】哈希表
    202310-MetaPhlAn4安装和使用方法-Anaconda3- centos9 stream
  • 原文地址:https://blog.csdn.net/Once_day/article/details/126267081