Win11笔记本安装Spacy失败求助:执行pip命令报错
问题描述
Win11笔记本上安装Spacy失败,已预装Python 3+版本及最新版pip,执行官网指定命令pip install -U spacy时安装进程报错终止。尝试过管理员/普通用户身份,在CMD、PowerShell及Anaconda Navigator中操作均未成功。
报错日志
C:\Users>pip install -U spacy Collecting spacy Using cached spacy-3.8.2.tar.gz (1.3 MB) Installing build dependencies ... error error: subprocess-exited-with-error × pip subprocess to install build dependencies did not run successfully. │ exit code: 1 ╰─> [67 lines of output] Ignoring numpy: markers 'python_version < "3.9"' don't match your environment Collecting setuptools Using cached setuptools-78.1.0-py3-none-any.whl.metadata (6.6 kB) Collecting cython<3.0,>=0.25 Using cached Cython-0.29.37-py2.py3-none-any.whl.metadata (3.1 kB) Collecting cymem<2.1.0,>=2.0.2 Using cached cymem-2.0.11-cp313-cp313-win_amd64.whl.metadata (8.8 kB) Collecting preshed<3.1.0,>=3.0.2 Using cached preshed-3.0.9.tar.gz (14 kB) Installing build dependencies: started Installing build dependencies: finished with status 'done' Getting requirements to build wheel: started Getting requirements to build wheel: finished with status 'done' Preparing metadata (pyproject.toml): started Preparing metadata (pyproject.toml): finished with status 'done' Collecting murmurhash<1.1.0,>=0.28.0 Using cached murmurhash-1.0.12-cp313-cp313-win_amd64.whl.metadata (2.2 kB) Collecting thinc<8.4.0,>=8.3.0 Using cached thinc-8.3.6-cp313-cp313-win_amd64.whl.metadata (15 kB) Collecting numpy<2.1.0,>=2.0.0 Using cached numpy-2.0.2.tar.gz (18.9 MB) Installing build dependencies: started Installing build dependencies: finished with status 'done' Getting requirements to build wheel: started Getting requirements to build wheel: finished with status 'done' Installing backend dependencies: started Installing backend dependencies: finished with status 'done' Preparing metadata (pyproject.toml): started Preparing metadata (pyproject.toml): finished with status 'error' error: subprocess-exited-with-error Preparing metadata (pyproject.toml) did not run successfully. exit code: 1 [21 lines of output] + C:\Users\ssswi\AppData\Local\Programs\Python\Python313\python.exe C:\Users\ssswi\AppData\Local\Temp\pip-install-5k8m2o0u\numpy_2290c26df8114c04b8fa71797b9618ea\vendored-meson\meson\meson.py setup C:\Users\ssswi\AppData\Local\Temp\pip-install-5k8m2o0u\numpy_2290c26df8114c04b8fa71797b9618ea C:\Users\ssswi\AppData\Local\Temp\pip-install-5k8m2o0u\numpy_2290c26df8114c04b8fa71797b9618ea\.mesonpy-9wuf4zzx -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --native-file=C:\Users\ssswi\AppData\Local\Temp\pip-install-5k8m2o0u\numpy_2290c26df8114c04b8fa71797b9618ea\.mesonpy-9wuf4zzx\meson-python-native-file.ini The Meson build system Version: 1.4.99 Source dir: C:\Users\ssswi\AppData\Local\Temp\pip-install-5k8m2o0u\numpy_2290c26df8114c04b8fa71797b9618ea Build dir: C:\Users\ssswi\AppData\Local\Temp\pip-install-5k8m2o0u\numpy_2290c26df8114c04b8fa71797b9618ea\.mesonpy-9wuf4zzx Build type: native build Project name: NumPy Project version: 2.0.2 WARNING: Failed to activate VS environment: Could not parse vswhere.exe output ..\meson.build:1:0: ERROR: Unknown compiler(s): [['icl'], ['cl'], ['cc'], ['gcc'], ['clang'], ['clang-cl'], ['pgcc']] The following exception(s) were encountered: Running `icl ""` gave "[WinError 2] The system cannot find the file specified" Running `cl /?` gave "[WinError 2] The system cannot find the file specified" Running `cc --version` gave "[WinError 2] The system cannot find the file specified" Running `gcc --version` gave "[WinError 2] The system cannot find the file specified" Running `clang --version` gave "[WinError 2] The system cannot find the file specified" Running `clang-cl /?` gave "[WinError 2] The system cannot find the file specified" Running `pgcc --version` gave "[WinError 2] The system cannot find the file specified" A full log can be found at C:\Users\ssswi\AppData\Local\Temp\pip-install-5k8m2o0u\numpy_2290c26df8114c04b8fa71797b9618ea\.mesonpy-9wuf4zzx\meson-logs\meson-log.txt [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed Encountered error while generating package metadata. See above for output. note: This is an issue with the package mentioned above, not pip. hint: See above for details. [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error × pip subprocess to install build dependencies did not run successfully. │ exit code: 1 ╰─> See above for output. note: This error originates from a subprocess, and is likely not a problem with pip.
解决方案
1. 安装C/C++编译工具
报错核心是系统缺少C/C++编译器,numpy 2.0+需要编译环境支持:
- 下载安装Microsoft Visual C++ Build Tools,勾选「Desktop development with C++」组件,安装完成后重启终端再执行Spacy安装命令。
- 安装后可通过打开VS开发者命令提示符,或手动将VS的bin目录添加到系统PATH,确保
cl.exe能在终端正常调用。
2. 指定兼容的numpy版本
Spacy 3.8.2无需强制依赖numpy 2.0+,可先安装低版本numpy再安装Spacy:
pip install numpy<2.0 pip install -U spacy
3. 使用预编译wheel包
直接下载对应Python版本和系统的Spacy预编译.whl文件,通过本地文件安装:
pip install path/to/spacy-3.8.2-cp313-cp313-win_amd64.whl
4. 通过conda安装(Anaconda环境)
conda会自动处理依赖和编译问题,适合Anaconda用户:
conda install -c conda-forge spacy
内容的提问来源于stack exchange,提问作者Sachin Shanbhag
相关产品推荐
相关产品推荐

