插件窝 干货文章 在Linux上使用Visual Studio Code进行数据科学的推荐配置

在Linux上使用Visual Studio Code进行数据科学的推荐配置

Python Jupyter 扩展 数据 327    来源:    2025-04-16

Visual Studio Code 在 Linux 上用于数据科学的推荐配置

核心扩展推荐

  1. Python 扩展 (由 Microsoft 提供)

    • 提供 IntelliSense、linting、调试、代码导航等核心功能
    • 支持 Jupyter Notebooks
  2. Jupyter 扩展

    • 直接在 VS Code 中运行 Jupyter Notebooks
    • 支持交互式开发和可视化
  3. Pylance (Python 语言服务器)

    • 提供超快的 Python 类型检查
    • 比传统 Python 语言服务器更智能的补全
  4. Data Wrangler (Microsoft 提供)

    • 交互式数据清理和转换工具
    • 类似 Excel/Pandas 的界面

其他有用扩展

  • GitLens - 增强的 Git 功能
  • Docker - 容器化开发支持
  • Remote - SSH - 远程开发支持
  • Excel Viewer - 查看 CSV/Excel 文件
  • Rainbow CSV - 彩色高亮 CSV 文件
  • SQLTools - 数据库连接和查询工具

推荐设置 (settings.json)

{
    "python.linting.enabled": true,
    "python.linting.pylintEnabled": true,
    "python.formatting.provider": "black",
    "python.languageServer": "Pylance",
    "jupyter.askForKernelRestart": false,
    "jupyter.sendSelectionToInteractiveWindow": true,
    "editor.renderWhitespace": "selection",
    "editor.rulers": [88],
    "python.analysis.typeCheckingMode": "basic",
    "files.autoSave": "afterDelay",
    "python.testing.pytestEnabled": true
}

终端配置

  1. 推荐使用 zshbash 配合 conda 环境
  2. 安装 tmux 用于会话管理
  3. 考虑使用 fish shell 获得更好的自动补全

Python 环境设置

  1. 推荐使用 condapyenv 管理 Python 环境
  2. 创建专用数据科学环境:

    conda create -n datascience python=3.9 pandas numpy scikit-learn matplotlib jupyter
    
  3. 在 VS Code 中选择正确的 Python 解释器 (Ctrl+Shift+P → "Python: Select Interpreter")

性能优化

  1. 启用硬件加速渲染:

    {
       "editor.hardwareAcceleration": "on",
       "terminal.integrated.gpuAcceleration": "on"
    }
    
  2. 对于大型数据集,考虑禁用某些功能:

    {
       "python.analysis.diagnosticMode": "workspace",
       "python.analysis.useLibraryCodeForTypes": false
    }
    

数据可视化

  1. 安装交互式可视化扩展:

    • Plotly 支持
    • Vega Viewer 用于 Vega-Lite 可视化
  2. 配置 Jupyter 以在 VS Code 中显示内联图表:

    {
       "jupyter.enablePlotViewer": true,
       "jupyter.plotting.savePlotDir": "~/vscode_plots"
    }
    

调试配置

  1. 为 Python 脚本设置 launch.json:

    {
       "version": "0.2.0",
       "configurations": [
           {
               "name": "Python: Current File",
               "type": "python",
               "request": "launch",
               "program": "${file}",
               "console": "integratedTerminal",
               "justMyCode": true
           }
       ]
    }
    
  2. 对于 Jupyter Notebooks,可以直接使用内置的调试功能

远程开发

  1. 使用 Remote - SSH 扩展连接远程服务器
  2. 或使用 Remote - Containers 扩展在 Docker 容器中开发

键盘快捷键

  • Ctrl+Shift+P: 打开命令面板
  • Ctrl+,: 打开设置
  • Ctrl+Shift+E: 资源管理器
  • Ctrl+Shift+X: 扩展视图
  • Ctrl+Shift+J: 打开 Jupyter Notebook
  • Shift+Enter: 运行选中的代码单元格

这个配置提供了强大的数据科学开发环境,结合了 VS Code 的轻量级特性和专业的数据科学工具链。