当前位置:   article > 正文

【Python】【VS Code】VS Code中python.json和setting.json文件配置说明_vscode python setting.json

vscode python setting.json

目录

1. python.json配置

2. setting.json配置

3. 解决中文乱码

4. 实现效果


1. python.json配置

           python.json 获取步骤:文件 -> 首选项 -> 配置用户代码片段 -> python

           此为VS Code的头文件设置,复制以下内容到 python.json

  1. {
  2. "HEADER":{
  3. "prefix": "pyheader",
  4. "body": [
  5. "#!/usr/bin/env python3",
  6. "# _*_ coding : UTF-8 _*_",
  7. "# 开发团队 :ALL",
  8. "# 开发人员 :Admin",
  9. "# 开发时间 :$CURRENT_YEAR/$CURRENT_MONTH/$CURRENT_DATE $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND",
  10. "# 文件名称 :$TM_FILENAME",
  11. "# 开发工具 :Visual Studio Code",
  12. "",
  13. "",
  14. "",
  15. "if __name__ == '__main__':",
  16. "$0"
  17. ],
  18. }
  19. }

用法:编辑一个.py文件,输入pyheader,就可以补全以下内容啦

  1. #!/usr/bin/env python3
  2. # _*_ coding : UTF-8 _*_
  3. # 开发团队 :ST
  4. # 开发人员 :Jly
  5. # 开发时间 :2024/02/19 19:30:06
  6. # 文件名称 :code_statistics.py
  7. # 开发工具 :Visual Studio Code
  8. if __name__ == '__main__':

2. setting.json配置

        setting.json获取步骤:文件 -> 首选项 -> 设置

        此为VS Code的头文件设置,涉及到环境配置、代码颜色、行间距、字体粗细、中文环境配置等等

  1. {
  2. "security.workspace.trust.untrustedFiles": "open",
  3. "workbench.colorTheme": "Oceanic Next (dimmed bg)",
  4. "workbench.iconTheme": "material-icon-theme",
  5. "bracket-pair-colorizer-2.depreciation-notice": false,
  6. "editor.lineHeight": 24, //控制行间距
  7. "editor.fontWeight": "normal", // 控制字体粗细
  8. "editor.tokenColorCustomizations": {"comments": "#00ff7f",
  9. "keywords": "#eb6689",
  10. "numbers": "#00eeff",
  11. "functions": "#ea65f9"
  12. }, //控制字体颜色
  13. "python.defaultInterpreterPath": "D:\\soft\\Anaconda3\\python.exe",
  14. //"python.linting.flake8Enabled": true,
  15. //"python.formatting.provider": "yapf",
  16. //"python.linting.flake8Args": ["--max-line-length=248"],
  17. //"python.linting.pylintEnabled": false,
  18. "python.autoComplete.extraPaths": ["D:/soft/Anaconda3/lib/site-packages",],
  19. "python.analysis.extraPaths": ["D:/soft/Anaconda3",],
  20. //"vsicons.dontShowNewVersionMessage": true,
  21. // 配置python语言正常输出中文的环境
  22. "code-runner.executorMap": {
  23. "python":"set PYTHONIOENCODING=utf8 && $pythonPath -u $fullFileName"},
  24. "code-runner.respectShebang": false,
  25. "editor.unicodeHighlight.includeStrings": false,
  26. "editor.unicodeHighlight.includeComments": false,
  27. //终端颜色配置
  28. "terminal.integrated.inheritEnv": false,
  29. "workbench.colorCustomizations": {
  30. "terminal.background": "#200707",
  31. "terminal.foreground": "#b4d6af",
  32. "terminalCursor.background": "#D8D8D8",
  33. "terminalCursor.foreground": "#D8D8D8",
  34. "terminal.ansiBlack": "#181818",
  35. "terminal.ansiBlue": "#0b5e7c",
  36. "terminal.ansiBrightBlack": "#585858",
  37. // 终端命令行 lm@os:
  38. "terminal.ansiBrightBlue": "#39b9e7",
  39. "terminal.ansiBrightCyan": "#86C1B9",
  40. "terminal.ansiBrightGreen": "#ca530f",
  41. "terminal.ansiBrightMagenta": "#BA8BAF",
  42. "terminal.ansiBrightRed": "#AB4642",
  43. "terminal.ansiBrightWhite": "#F8F8F8",
  44. "terminal.ansiBrightYellow": "#f788f7",
  45. "terminal.ansiCyan": "#86C1B9",
  46. "terminal.ansiGreen": "#b57b6c",
  47. "terminal.ansiMagenta": "#BA8BAF",
  48. "terminal.ansiRed": "#AB4642",
  49. "terminal.ansiWhite": "#D8D8D8",
  50. "terminal.ansiYellow": "#F7CA88",
  51. "terminal.integrated.cursorBlinking": true,
  52. "terminal.integrated.lineHeight": 1.6,
  53. "terminal.integrated.letterSpacing": 0.1,
  54. "terminal.integrated.fontFamily": "Lucida Console", //字体设置
  55. "terminal.integrated.shell.linux": "/bin/zsh",
  56. },
  57. "[python]": {
  58. "editor.formatOnType": true
  59. },
  60. "vsicons.dontShowNewVersionMessage": true,
  61. "settingsSync.ignoredExtensions": [
  62. ],
  63. "settingsSync.ignoredSettings": [
  64. ],
  65. "window.zoomLevel": -1,
  66. "editor.codeActionsOnSave": {
  67. }
  68. }

3. 解决中文乱码

        在setting.json文件里面增加以下内容即可

  1. // 配置python语言正常输出中文的环境
  2. "code-runner.executorMap": {
  3. "python":"set PYTHONIOENCODING=utf8 && $pythonPath -u $fullFileName"},
  4. "code-runner.respectShebang": false
  5. },

4. 实现效果

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/356825
推荐阅读
相关标签
  

闽ICP备14008679号