VSCode Python 配置
相关插件
VSCode 与 Python 有关的插件如下:(巨硬把这些插件拆分的实在太细了)
- Python
- Python Debugger
- Python Environments
- Pylance:Python语言服务器,支持自动补全、代码提示等
- Black Formatter:代码格式化(需要通过
conda/pip
下载对应模块) - Flake8:代码静态分析(需要通过
conda/pip
下载对应模块) - Jupyter 插件包:
- Jupyter
- Jupyter Keymap
- Jupyter Cell Tags
- Jupyter Notebook Renderers
- Jupyter Slide show
注意需要单独下载 black 和 flake8 包,例如 1
conda install black flake8
如果语法高亮等出现问题,最好先清理相关的配置缓存并重启VSCode,可以解决不少问题。
VSCode 插件配置
下面是目前VSCode关于Python的配置(2025年7月)
编辑器配置 1
2
3
4
5
6
7
8"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnType": true,
"editor.unicodeHighlight.allowedLocales": {
"zh-hans": true,
"zh-hant": true
},
},
Python 配置 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15//[[Python]]
"python.terminal.activateEnvironment": false,
"python.languageServer": "Pylance",
"python.analysis.typeCheckingMode": "basic",
"flake8.severity": {
"E": "Hint",
"F": "Warning"
},
"black-formatter.args": [
"--verbose",
],
"flake8.showNotifications": "onError",
"python.analysis.diagnosticSeverityOverrides": {
"reportGeneralTypeIssues": "none"
},
jupyter notebook 配置 1
2
3
4
5
6
7
8
9
10
11
12"jupyter.askForKernelRestart": false,
"notebook.cellToolbarLocation": {
"default": "right",
"jupyter-notebook": "right"
},
"notebook.markup.fontSize": 16,
"notebook.output.textLineLimit": 50,
"notebook.output.scrolling": true,
"notebook.lineNumbers": "on",
"notebook.outline.showCodeCells": true,
"notebook.outline.showMarkdownHeadersOnly": false,
"notebook.diff.ignoreMetadata": true,