Visual Studio Code builds a python development environment

Source: Internet
Author: User


Visual Studio Code builds a python development environment
  • Python installation (Mac comes with)
  • Visual Studio Code Installation
  • Visual Studio Code Installation python plugin
      • Command + P to open the commands input interface
      • Enter ext install python install python plugin
  • Installation configuration Flake8 (automatic error Checking tool)
      • Install Flake8 pip install Flake8 in a Python environment
      • User-Preferences-modify configuration in Workspace settings (user settings can also) "python.linting.flake8Enabled": True
  • Installation configuration YAPF (auto Format Code tool)
      • Python environment installation YAPF pip install Yapf
      • User-Preferences-modify configuration in Workspace settings (user settings can also) "Python.formatting.provider": "Yapf"
      • Command + SHIFT + F format code
  • Configure COMMAND + Shift + B to run the code
      • Open or create a new Python source file, press the shortcut key toCtrl+Shift+Brun, VSC will promptNo task runner configured., click "Configure Task Runner", select "Others", enter the following content and save:

        {
            // 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"
        }
  • Configuring the VITUALENV Runtime Environment
      • User-Preferences-modify configuration in Workspace settings (user settings can also) "Python.pythonpath": "${workspaceroot}/venv/bin/python"
  • Install the linting (Code Format Checker tool)
      • Install linting pip install pylint in a Python environment
      • Pylint is turned on by default after installing the Python plugin
  • Configure Display space characters
      • User-Preferences-modify configuration in Workspace settings (user settings can also) "Editor.renderwhitespace": "All"
  • Configuration ignores non-code file display
      • User-Preferences-modify configuration in Workspace settings (user settings also available)
"Files.exclude":{ "**/.git": true, "**/." SVN ": true, " **/.HG ": true, "**/. Ds_store ": true, " **/*.pyc ":true}
    • Full Workspace configuration file
  1. //Put settings in this file to override defaults and user settings.
  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. //Configure glob mode to exclude files and folders.
  9. "files.exclude":{
  10. "**/.git": true,
  11. "**/.svn": true,
  12. "**/.hg": true,
  13. "**/.DS_Store": true,
  14. "**/*.pyc":true
  15. }
  16. }
    • Configure Code Snippets
      • code-Preferences-User code snippet, select Python
      • In the configuration file, enter the content you want to define, and the field has the following meanings:
Prefix: This parameter is a quick entry to use the code segment. For example, if the log is used, the input log will be intellisense.
Body : This is the body of the code segment. The code to be set is placed here, and the line break between strings is separated by \r\n newline. Note that if the value contains special characters, it needs to be escaped.
$1 : This is the location of the cursor.
$2: After using this parameter, the next position of the cursor will start another line, press tab to switch quickly.
Description : description of the code segment, description when using IntelliSense
    • The complete configuration file instance is as follows:
  1. {
  2. /*
  3. //place  Your Snippets forpython hereeach 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 would be Expanded and inserted possible variables are:
  5. // $1,< Span class= "PLN" > $2 for tab stops, $0 for the final cursor position ,and ${1 :label}, ${< Span class= "lit" >2:another}for  placeholders. Placeholderswith&NBSP;THE&NBSP;
  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 : General comparison xx method",
  23. "Input Parameters: jsonastr,jsonbstr",
  24. "Return Value : None",
  25. "‘‘‘"
  26. ],
  27. "description":"Input the class or function notes!"
  28. }
  29. }
    • How to call: Enter the Itne carriage return in the Python file, then enter the definition code snippet
    • Configure shortcut keys
      • code-Preferences-Keyboard mapping extension
    • Configuring themes
      • code-Preferences-color theme
      • code-Preferences-file icon theme


Visual Studio Code builds a python development environment


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.