zoukankan      html  css  js  c++  java
  • Visual Studio Code搭建python开发环境

    • python安装(Mac下自带)
    • Visual Studio Code 安装
    • Visual Studio Code 安装python插件
      • command + P 打开命令输入界面
      • 输入ext install python 安装python插件
    • 安装配置flake8(自动错误检查工具)
      • python环境中安装flake8    pip install flake8   
      • 用户-首选项-工作区设置中修改配置(用户设置也可以)  "python.linting.flake8Enabled": true
    • 安装配置yapf(自动格式化代码工具)
      • python环境安装yapf    pip install yapf
      • 用户-首选项-工作区设置中修改配置(用户设置也可以)  "python.formatting.provider": "yapf"
      • Command + shift + F 格式化代码
    • 配置Command + Shift + B 运行代码
      • 打开或新建一个python源文件,按下快捷键Ctrl+Shift+B运行,VSC会提示No task runner configured.,点击“Configure Task Runner”,选择“Others”,输入以下内容并保存:

        {
            // See https://go.microsoft.com/fwlink/?LinkId=733558
            // for the documentation about the tasks.json format
            "version": "0.1.0",
            "command": "${workspaceRoot}/venv/bin/python",
            "isShellCommand": true,
            "args": ["${file}"],
            "showOutput": "always"
        }
    • 配置vitualenv运行环境
      • 用户-首选项-工作区设置中修改配置(用户设置也可以)"python.pythonPath": "${workspaceRoot}/venv/bin/python"
    • 安装Linting(代码格式检查工具)
      • python环境中安装linting    pip install pylint
      • 安装完python插件后pylint是默认开启的
    • 配置显示空格字符
      • 用户-首选项-工作区设置中修改配置(用户设置也可以)"editor.renderWhitespace": "all"
    • 配置忽略非代码文件显示
      • 用户-首选项-工作区设置中修改配置(用户设置也可以)
    "files.exclude":{
    "**/.git": true,
    "**/.svn": true,
    "**/.hg": true,
    "**/.DS_Store": true,
    "**/*.pyc":true
    }
    • 完整工作区配置文件
    1. //将设置放入此文件中以覆盖默认值和用户设置。
    2. {
    3. "python.pythonPath":"${workspaceRoot}/venv/bin/python",
    4. "editor.renderWhitespace":"all",
    5. "python.linting.pylintEnabled": false,
    6. "python.linting.flake8Enabled": true,
    7. "python.formatting.provider":"yapf",
    8. //配置 glob 模式以排除文件和文件夹。
    9. "files.exclude":{
    10. "**/.git": true,
    11. "**/.svn": true,
    12. "**/.hg": true,
    13. "**/.DS_Store": true,
    14. "**/*.pyc":true
    15. }
    16. }
    • 配置代码片段
      • Code—首选项—用户代码片段,选择python
      • 在配置文件中,输入想要定义的内容,字段含义如下:
    prefix      :这个参数是使用代码段的快捷入口,比如这里的log在使用时输入log会有智能感知.
    body        :这个是代码段的主体.需要设置的代码放在这里,字符串间换行的话使用
    换行符隔开.注意如果值里包含特殊字符需要进行转义.
    $1          :这个为光标的所在位置.
    $2          :使用这个参数后会光标的下一位置将会另起一行,按tab键可进行快速切换
    description :代码段描述,在使用智能感知时的描述
      • 完整配置文件实例如下:
    1. {
    2. /*
    3. //Place your snippets forPython here.Each snippet is defined under a snippet name and has a prefix, body and
    4. // description.The prefix is what is used to trigger the snippet and the body will be expanded and inserted.Possible variables are:
    5. // $1, $2 for tab stops, $0 for the final cursor position,and ${1:label}, ${2:another}for placeholders.Placeholderswith the
    6. // same ids are connected.
    7. //Example:
    8. "Print to console":{
    9. "prefix":"log",
    10. "body":[
    11. "console.log('$1');",
    12. "$2"
    13. ],
    14. "description":"Log output to console"
    15. }
    16. */
    17. "Input Note":{
    18. "prefix":"itne",
    19. "body":[
    20. "'''",
    21. "Function Name : diff_Json_Same",
    22. "Function : 通用比较xx方法",
    23. "Input Parameters: jsonastr,jsonbstr",
    24. "Return Value : None",
    25. "'''"
    26. ],
    27. "description":"Input the class or function notes!"
    28. }
    29. }
      • 调用方式:在python文件中输入itne回车,则输入定义代码片段
    • 配置快捷键
      • Code—首选项—键盘映射拓展
    • 配置主题
      • Code—首选项—颜色主题
      • Code—首选项—文件图标主题
     
     





  • 相关阅读:
    MD代码块指定语言类型
    spring通过bean名称,方法名,反射调用服务。
    h5魔塔开坑记
    意识流CSP2021游记
    Android开发byte version = 0x80错误: 不兼容的类型: 从int转换到byte可能会有损失
    Installed Build Tools revision 31.0.0 is corrupted. Remove and install again using the SDK Manager解决方法
    Android开发androidstudio调试smali代码
    Android开发修改手机ro.debuggable=1便于调试应用程序
    window环境下载Android系统源代码的方法
    android开发jni开发遍历文件夹下的文件以及目录
  • 原文地址:https://www.cnblogs.com/ceshisanren/p/6343774.html
Copyright © 2011-2022 走看看