在RHEL系统上部署并启动Spacy Displacy REST微服务
Got it, let's walk through exactly how to get spaCy Services up and running on your RHEL machine so you can hit that /ent endpoint locally. Here's a step-by-step breakdown that should cover everything you need:
1. Set up basic system dependencies
First, make sure your RHEL system has the core tools installed. Open your terminal and run:
- For RHEL 8/9 (using dnf):
sudo dnf install python3 python3-pip git -y - For RHEL 7 (using yum):
sudo yum install python3 python3-pip git -y
2. Use a virtual environment (highly recommended)
Isolating dependencies avoids messing with your system's default Python setup. Here's how to set one up:
- Create a virtual environment:
python3 -m venv spacy-services-env - Activate it (you'll see the environment name in your terminal prompt once active):
source spacy-services-env/bin/activate
3. Clone the spaCy Services repository
Grab the code from the official repo:git clone https://github.com/explosion/spacy-services
- Navigate into the cloned directory:
cd spacy-services
4. Install required packages
First, install all dependencies listed in the repo's requirements file:pip install -r requirements.txt
Next, you'll need a spaCy language model to power named entity recognition. Let's use the lightweight default English model:python -m spacy download en_core_web_sm
5. Start the API service
Launch the server using Uvicorn (the ASGI server specified in the repo):uvicorn main:app --host 0.0.0.0 --port 8000
You'll see output confirming the server is running on http://0.0.0.0:8000—this means it's accessible locally at http://localhost:8000.
6. Test the /ent endpoint
Keep the server running in your first terminal, then open a new window to send a test POST request with curl:curl -X POST -H "Content-Type: application/json" -d '{"text": "Apple is planning to acquire a UK-based startup for $2 billion"}' http://localhost:8000/ent
You’ll get a JSON response back listing all detected named entities (like "Apple" as ORG, "UK" as GPE, and "$2 billion" as MONEY).
Troubleshooting quick fixes
- If you can’t reach the endpoint, check if RHEL's firewalld is blocking port 8000. Open it with:
sudo firewall-cmd --add-port=8000/tcp --permanentsudo firewall-cmd --reload - If dependency installation fails, confirm your Python version is 3.7 or higher (spaCy requires this minimum version).
- If the model download times out, configure a proxy for
pipif you’re behind a corporate firewall.
内容的提问来源于stack exchange,提问作者Mohit

