跳到主要内容

Vscode安装python插件


Vscode安装python插件

🧩 一、核心插件

插件名称 VS Code 标识符 安装命令 作用说明
Python ms-python.python code --install-extension ms-python.python Python 基础支持、运行、测试和解释器选择。
Pylance ms-python.vscode-pylance code --install-extension ms-python.vscode-pylance 智能补全、类型分析和跳转。Python 扩展通常会把它作为可选依赖一起安装。
Jupyter ms-toolsai.jupyter code --install-extension ms-toolsai.jupyter 需要 .ipynb / Notebook 时再安装。

Jupyter Keymap、Cell Tags 等属于 Notebook 增强插件,不写 Notebook 时没必要全部安装。

💡 配置建议:
打开命令面板(Ctrl+Shift+P)→ 搜索 “Python: Select Interpreter” → 选择你想用的 Conda 或系统环境。


🧱 二、代码规范与格式化插件(提升质量)

插件名称 标识符 安装命令 功能
Black Formatter ms-python.black-formatter code --install-extension ms-python.black-formatter 自动格式化 Python 代码
isort ms-python.isort code --install-extension ms-python.isort 自动排序 import 导入语句
Flake8 ms-python.flake8 code --install-extension ms-python.flake8 静态检查,帮助发现风格和部分代码问题
Pylint ms-python.pylint code --install-extension ms-python.pylint 更严格的静态检查,可按项目需要安装
Pyright ms-pyright.pyright code --install-extension ms-pyright.pyright 独立的 Pyright 类型检查器;一般已经使用 Pylance 时不需要再同时安装

现在 Python 扩展已经不再支持旧的 python.formatting.* 和 python.linting.* 配置,格式化和 lint 都由对应工具扩展自己负责。Black 的常用配置可以这样写:

{
  "[python]": {
    "editor.defaultFormatter": "ms-python.black-formatter",
    "editor.formatOnSave": true
  },
  "isort.args": ["--profile", "black"]
}

🎨 三、界面与编辑增强插件

插件名称 标识符 功能
Better Comments aaron-bond.better-comments 高亮不同类型注释(例如:TODO, !, ?, *)
indent-rainbow oderwat.indent-rainbow 彩色缩进,快速发现缩进错误
Error Lens usernamehw.errorlens 将错误和警告直接显示在代码中行尾
GitLens eamodio.gitlens 增强 Git 支持,查看每行提交者与历史
Material Icon Theme PKief.material-icon-theme 让文件图标更直观美观
One Dark Pro zhuangtongfa.Material-theme 非常舒服的主题(深色)

🧠 四、辅助生产力插件

插件名称 标识符 功能
autoDocstring njpwerner.autodocstring 快速生成函数/类的 docstring
Python Snippets frhtylcn.pythonsnippets 常用 Python 代码模板
Code Runner formulahendry.code-runner 一键运行选中代码片段(非常方便)
Path Intellisense christian-kohler.path-intellisense 自动补全文件路径
Tabnine AI Autocomplete(可选) TabNine.tabnine-vscode 基于 AI 的智能代码补全

💡 Code Runner 推荐配置:

{
  "code-runner.executorMap": {
    "python": "python -u"
  },
  "code-runner.runInTerminal": true,
  "code-runner.ignoreSelection": false
}

注意这里的 python -u 使用的是终端里解析到的 python。如果它和 VS Code 当前选择的解释器不是同一个环境,运行结果会不一致;普通 Python 项目优先使用 Python 扩展自带的 Run Python File 更稳。


🧭 五、虚拟环境与终端优化插件

插件名称 标识符 功能
Python Environments ms-python.vscode-python-envs 管理和切换 venv、Conda、pyenv、Poetry 等 Python 环境;新版 Python 扩展正在逐步启用这套环境管理体验
Remote - WSL ms-vscode-remote.remote-wsl 在 WSL 中直接打开项目和运行 Python
Terminal Manager fabiospampinato.vscode-terminals 多终端工作流增强,可选

不需要单独安装一个叫“Conda”的 Jupyter 插件才能识别 Conda。Python / Python Environments 本身就支持发现 Conda 环境。

💡 提示:可以用 Ctrl + 反引号键 打开内置终端。想把 Git Bash 设为默认终端时:

{
  "terminal.integrated.defaultProfile.windows": "Git Bash"
}

🧰 六、进阶推荐(根据用途选)

用途 插件
数据分析 / 科学计算 Jupyter + Python Data Science Tools
Web 开发 Django / Flask Snippets, REST Client
机器学习 TensorBoard, Jupyter Notebook Renderers
区块链 / 密码学实验 Solidity + Python, Hex Editor
文档撰写 Markdown All in One, markdownlint

⚙️ 七、完整推荐 settings.json 示例

下面只保留当前仍有效、且比较通用的设置;Python 解释器建议用 Python: Select Interpreter 选择,不把某台电脑的 Conda 路径写死:

{
  "[python]": {
    "editor.defaultFormatter": "ms-python.black-formatter",
    "editor.formatOnSave": true
  },
  "python.analysis.typeCheckingMode": "basic",
  "isort.args": ["--profile", "black"],
  "editor.minimap.enabled": true,
  "editor.wordWrap": "on",
  "files.autoSave": "onFocusChange",
  "workbench.iconTheme": "material-icon-theme",
  "terminal.integrated.defaultProfile.windows": "Git Bash",
  "code-runner.executorMap": {
    "python": "python -u"
  },
  "code-runner.runInTerminal": true
}

如果使用 Flake8、Pylint 等检查器,直接安装相应扩展并在它自己的设置项中配置,不再使用旧的 python.linting.*。


🚀 一键安装命令合集

先在终端执行 code --version 确认 VS Code 命令行已经可用。Windows 通常由安装器把 code 加入 PATH;macOS 可以使用命令面板里的 Shell Command: Install ‘code’ command in PATH。

下面按自己的需要选择安装,不必全部装:

code --install-extension ms-python.python
code --install-extension ms-python.vscode-pylance
code --install-extension ms-python.vscode-python-envs
code --install-extension ms-toolsai.jupyter
code --install-extension ms-python.black-formatter
code --install-extension ms-python.flake8
code --install-extension ms-python.isort
code --install-extension aaron-bond.better-comments
code --install-extension oderwat.indent-rainbow
code --install-extension usernamehw.errorlens
code --install-extension eamodio.gitlens
code --install-extension PKief.material-icon-theme
code --install-extension zhuangtongfa.Material-theme
code --install-extension njpwerner.autodocstring
code --install-extension formulahendry.code-runner
code --install-extension christian-kohler.path-intellisense

文章作者: 0xdadream
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 0xdadream !
赏
评论

评论将在接近此处时加载,也可点击立即加载。

  目录