在AWS SageMaker中安装spaCy遇gcc报错,如何解决?
Hey there, let's tackle those two installation errors you're facing one by one—they're both tied to missing system-level tools needed to compile spaCy's dependencies. Here's how to fix them:
Why You're Seeing These Errors
gcc: error trying to exec 'cc1plus': execvp: No such file or directory: This happens because your SageMaker instance only has the C compiler (gcc) installed, but spaCy's dependencies require a C++ compiler (g++). Thecc1plusbinary is a core part of the C++ compiler suite, which is missing here.gcc: error: murmurhash/mrmr.cpp: No such file or directory: This pops up because you're missing Python development headers and other build tools required to compile low-level libraries likemurmurhash(a dependency spaCy uses for efficient hashing).
Step-by-Step Fixes
Option 1: Install Required System Tools (Recommended for Pip Installs)
First, install the necessary build dependencies directly in your Jupyter Notebook cell:
For Amazon Linux 2-based SageMaker Instances (Default)
Run this command to install the C++ compiler and Python development headers:
sudo yum install -y gcc-c++ python3-devel
For Ubuntu-based SageMaker Instances
If you're using an Ubuntu-backed instance, use these commands instead:
sudo apt-get update && sudo apt-get install -y g++ python3-dev
Once those tools are installed, re-run your spaCy installation command:
!pip install spacy
Option 2: Use Conda to Avoid Compilation (Easier Alternative)
If you don't want to deal with compiling from source, use Conda to install a pre-built version of spaCy. Most SageMaker instances come with Conda pre-configured, so run this in a notebook cell:
!conda install -c conda-forge spacy -y
This skips the build process entirely, which avoids both errors in one go.
Verify the Installation
After installation, test that spaCy loads correctly by running:
import spacy nlp = spacy.load("en_core_web_sm")
If this runs without errors, you're good to go!
内容的提问来源于stack exchange,提问作者Sujay DSa

