You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VSCode安装ipykernel失败求助:编译psutil需Microsoft VC++14.0+

VSCode安装ipykernel失败的解决办法

问题背景

在VSCode中运行Jupyter Notebook代码时,系统提示需安装ipykernel。运行的代码如下:

# Load the libraries to be used in the Analysis

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import warnings  # 修正原代码拼写错误

# Setup libraries settings and options
## Pandas setup
pd.set_option('display.max_columns', None)

## matplotlib setup
%matplotlib inline

## Seaborn setup
sns.set_context('notebook')
sns.set_style('whitegrid')
sns.set_palette('Blues_r')

# turn off warning for final notebook
warnings.filterwarnings('ignore')

尝试过程中的错误

  1. 选择VSCode内安装后,系统给出提示:

Running cells with 'Python 3.11.0 64-bit' requires ipykernel package.
Run the following command to install 'ipykernel' into the Python environment.
Command: 'c:/Users/Samir/AppData/Local/Programs/Python/Python311/python.exe -m pip install ipykernel -U --user --force-reinstall'

  1. 在Git Bash中执行python -m pip install ipykernel,触发编译错误:
\tests
      running build_ext
      building 'psutil._psutil_windows' extension
      error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for psutil
Failed to build psutil
ERROR: Could not build wheels for psutil, which is required to install pyproject.toml-based projects

可行解决办法

方法1:安装C++编译工具

错误核心是缺少Microsoft Visual C++ 14.0及以上版本的编译环境,psutil依赖它完成编译:

  • 打开Microsoft Visual C++ Build Tools安装程序(无需安装完整Visual Studio)
  • 勾选「Desktop development with C++」工作负载,确保包含MSVC v14x工具链、Windows SDK等必要组件
  • 完成安装后重启终端,重新执行python -m pip install ipykernel

方法2:安装预编译的psutil包

如果不想安装编译工具,可直接使用预编译的psutil轮子文件:

  • 获取对应Python 3.11、Windows 64位的psutil .whl文件
  • 执行pip install 路径/psutil-x.x.x-cp311-none-win_amd64.whl完成psutil安装
  • 之后再执行pip install ipykernel

方法3:使用conda环境(已安装Anaconda/Miniconda时)

conda会自动处理依赖的编译问题,无需手动安装编译工具:

  • 打开终端,创建并激活新环境:
    conda create -n py311 python=3.11
    conda activate py311
    
  • 安装ipykernel:
    conda install ipykernel
    
  • 在VSCode中选择这个conda环境作为Jupyter的运行内核

内容的提问来源于stack exchange,提问作者hamdy-samir

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 18:25:35