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        :这个是代码段的主体.需要设置的代码放在这里,字符串间换行的话使用\r\n换行符隔开.注意如果值里包含特殊字符需要进行转义.
$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—首选项—文件图标主题
 
 





posted @ 2017-01-23 12:19  测试散人  阅读(18507)  评论(0编辑  收藏  举报