pip安装spaCy失败,报错提示NumPy需要GCC >= 8.4
pip安装spaCy失败,报错提示NumPy需要GCC >= 8.4
问题描述
我想在项目中使用spaCy,但通过pip安装失败,命令行报错如下:
pip install 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 ╰─> [103 lines of output] Ignoring numpy: markers 'python_version < "3.9"' don't match your environment Collecting setuptools Using cached setuptools-76.0.0-py3-none-any.whl.metadata (6.7 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.2.tar.gz (193 kB) Installing build dependencies: started Installing build dependencies: finished with status 'error' error: subprocess-exited-with-error pip subprocess to install build dependencies did not run successfully. exit code: 1 [65 lines of output] Ignoring numpy: markers 'python_version < "3.9"' don't match your environment Collecting setuptools Using cached setuptools-76.0.0-py3-none-any.whl.metadata (6.7 kB) Collecting cython<3.0,>=0.25 Using cached Cython-0.29.37-py2.py3-none-any.whl.metadata (3.1 kB) Collecting murmurhash<1.1.0,>=1.0.2 Using cached murmurhash-1.0.12-cp313-cp313-win_amd64.whl.metadata (2.2 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 blis<1.1.0,>=1.0.0 Using cached blis-1.0.2-cp313-cp313-win_amd64.whl.metadata (7.8 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 [19 lines of output] + C:\Users\ronal\AppData\Local\Programs\Python\Python313\python.exe C:\Users\ronal\AppData\Local\Temp\pip-install-bpp4n0ch\numpy_744bbb085194411e9f392421c1dd5e5e\vendored-meson\meson\meson.py setup C:\Users\ronal\AppData\Local\Temp\pip-install-bpp4n0ch\numpy_744bbb085194411e9f392421c1dd5e5e C:\Users\ronal\AppData\Local\Temp\pip-install-bpp4n0ch\numpy_744bbb085194411e9f392421c1dd5e5e\.mesonpy-8ls7xc0w -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --native-file=C:\Users\ronal\AppData\Local\Temp\pip-install-bpp4n0ch\numpy_744bbb085194411e9f392421c1dd5e5e\.mesonpy-8ls7xc0w\meson-python-native-file.ini The Meson build system Version: 1.4.99 Source dir: C:\Users\ronal\AppData\Local\Temp\pip-install-bpp4n0ch\numpy_744bbb085194411e9f392421c1dd5e5e Build dir: C:\Users\ronal\AppData\Local\Temp\pip-install-bpp4n0ch\numpy_744bbb085194411e9f392421c1dd5e5e\.mesonpy-8ls7xc0w Build type: native build Project name: NumPy Project version: 2.0.2 C compiler for the host machine: gcc (gcc 6.3.0 "gcc (MinGW.org GCC-6.3.0-1) 6.3.0") C linker for the host machine: gcc ld.bfd 2.28 C++ compiler for the host machine: c++ (gcc 6.3.0 "c++ (MinGW.org GCC-6.3.0-1) 6.3.0") C++ linker for the host machine: c++ ld.bfd 2.28 Cython compiler for the host machine: cython (cython 3.0.12) Host machine cpu family: x86 Host machine cpu: x86 ..\meson.build:28:4: ERROR: Problem encountered: NumPy requires GCC >= 8.4 A full log can be found at C:\Users\ronal\AppData\Local\Temp\pip-install-bpp4n0ch\numpy_744bbb085194411e9f392421c1dd5e5e\.mesonpy-8ls7xc0w\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. [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.
我尝试用
pip install spacy安装spaCy但一直失败,现在无法导入spaCy,希望有人能帮忙解决这个问题。
解决方案
从报错日志里能一眼看到核心问题:你的系统当前使用的GCC版本是6.3.0,而NumPy 2.0.2要求GCC版本至少8.4,这才引发了后续一系列安装失败的连锁反应。下面给你几个实用的解决办法,按推荐程度排序:
1. 先安装兼容旧GCC的NumPy版本,再安装spaCy
这是最快的临时解决方案,不需要升级编译器:
- 先手动安装对GCC要求更低的NumPy 1.26.4版本:
pip install numpy==1.26.4 - 安装完成后,再执行spaCy的安装命令:
这样pip会复用已安装的兼容版NumPy,不会再去尝试编译需要高版本GCC的NumPy 2.x。pip install spacy
2. 升级你的GCC编译器(长期解决方案)
如果之后还需要安装其他需要编译的Python包,升级编译器是一劳永逸的办法:
- Windows系统:
推荐使用MinGW-w64来安装高版本GCC:- 下载MinGW-w64的官方安装器,选择x86_64架构,GCC版本选择8.4及以上(比如12.x版本更稳定)
- 安装完成后,把MinGW安装目录下的
bin文件夹添加到系统环境变量PATH中 - 打开新的命令行窗口,输入
gcc --version确认版本已更新成功
- Linux系统:
根据你的发行版用包管理器升级:- Debian/Ubuntu系:
sudo apt update && sudo apt install gcc-8 g++-8 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 100 - RHEL/CentOS系:
sudo dnf install gcc8
- Debian/Ubuntu系:
3. 用Conda安装(如果你的环境有Conda)
Conda的预编译包已经处理好了所有编译依赖问题,不需要自己管编译器版本:
conda install -c conda-forge spacy
备注:内容来源于stack exchange,提问作者Ronal George
相关产品推荐
相关产品推荐

