# Fix "OSError: [E941] Can't find model 'en'" in spacy.load

Yes. An agent maps each spaCy 2 shortcut your service loads to its full pipeline name, fixes the download step in the README and Dockerfile, and tests the endpoint.

[Run this on Rush](https://cloud.getrush.ai/run/fix-spacy-cant-find-model-en/spacy/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

spaCy 3 retired the one-word model shortcuts. On 3.8.18, `spacy.load("en")` raises `OSError: [E941] Can't find model 'en'. It looks like you're trying to load a model from a shortcut, which is obsolete as of spaCy v3.0`, and tells you to use `spacy.load("en_core_web_sm")`. The package carries the table it uses for that message, `OLD_MODEL_SHORTCUTS`, which maps `en` to `en_core_web_sm`, `de` to `de_core_news_sm`, `es`, `pt`, `fr`, `it`, `nl`, `el`, `nb` and `lt` to their `_core_news_sm` packages and `xx` to `xx_ent_wiki_sm`. `python -m spacy download en` still works, with a warning that shortcuts are deprecated, and installs `en_core_web_sm`; the code that loads `en` afterwards fails anyway, because the package is importable only under its full name.

web64/nlpserver is a Flask service that wraps several NLP libraries behind HTTP endpoints for callers in other languages. `requirements.txt` lists `spacy` with no version. The `/spacy/entities` handler in `nlpserver.py` reads a `lang` form field, defaults it to `en` on line 120, and calls `spacy.load(lang)` on line 124, so the model name comes straight from the request and the default is exactly the shortcut spaCy 3 refuses. `wip/spacy_entities.py` has `spacy.load("en")` on line 5. The README's Step 3 tells users to run `python3 -m spacy download en`, `es` and `xx`, and `docker/Dockerfile` does the same for `en` and `xx` after `pip install -r requirements.txt`, on a `python:3.8.5-slim-buster` base. With no pin, a fresh install gets spaCy 3 and every entity request answers a 500.

The agent reproduces it in a virtual environment: install the requirements, run `python -m spacy download en`, confirm the warning and the installed `en_core_web_sm`, then call `spacy.load("en")` and keep the E941 traceback. The fix has two parts. In `nlpserver.py` it resolves the request's `lang` through a small table before loading: a full name is used as given, a two-letter code is mapped to its `_core_web_sm` or `_core_news_sm` package, and an unknown code answers a JSON error instead of a traceback. The README and the Dockerfile change their download lines to the full package names, and `requirements.txt` gets a lower bound so the install and the docs describe the same major version.

To test the endpoint without the rest of the stack, the agent starts the Flask app in the sandbox with only spaCy installed, since the other libraries are imported inside their handlers and `/status` reports what is missing, and posts `text=...` with `lang=en` and with no `lang` to `/spacy/entities`, checking the JSON carries entity labels. The README's own example sentence serves as input. It also loads each language the Dockerfile installs once, to show `xx` resolves to `xx_ent_wiki_sm`. Nothing is pushed to the Docker image and the service is not deployed; the sandbox has no Docker, and the Dockerfile change is checked by reading, with the build left to CI.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "This service fails with OSError: [E941] Can't find model 'en' when spacy.load runs. Read requirements.txt, the README and the Dockerfile and report how spacy is specified and which models the docs tell users to download. In a clean virtual environment install the requirements, run python -m spacy download en, and reproduce the error by calling spacy.load('en'); keep the traceback and the installed spacy version. Find every spacy.load call with file and line, and note which take the model name from a request parameter. Fix the loading so a two-letter language code resolves to the full pipeline package spaCy 3 expects (read the mapping from the installed spacy package, not from memory), a full package name passes through unchanged, and an unknown code returns a JSON error. Update the download commands in the README and the Dockerfile to full package names and add a lower bound on spacy. Start the Flask app with only spacy installed and test the entity endpoint with lang=en and with no lang, using the README's example sentence, and include the responses. Do not build the Docker image and do not deploy. Open a pull request with the traceback, the list of load calls, and the endpoint responses.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

A pull request that touches `nlpserver.py`, `README.md`, `docker/Dockerfile` and `requirements.txt`. The description leads with the E941 traceback from the sandbox and the installed version, then the mapping the code now applies, taken from the installed package's own `OLD_MODEL_SHORTCUTS` table so the names match what `spacy download` installs.

The record of the run holds the download command with its deprecation warning, the failing load, the Flask app starting, and the two `curl` calls to `/spacy/entities` with their JSON. A reviewer can read the entity labels for the README's sentence and compare them with the response example the README already shows.

Before merging, a reviewer rebuilds the Docker image in CI, since the sandbox did not, and decides whether the other language models the service advertises should be installed in the image or left to the README. The pull request lists the codes the mapping covers and the one it was tested with.

## Run it on every 5xx on an endpoint

A service like this one fails on the first entity request after a rebuild, which an uptime check or an error tracker sees as a 500. A Grafana contact point can call a Rush `webhook` trigger directly with `Authorization: Bearer <its secret>` in a custom header, so an alert on the endpoint's error rate starts one run with the alert payload after the prompt. Set the trigger call's `Idempotency-Key` to the alert's fingerprint so a repeated notification starts no second run.

Sentry cannot send that header; a handler on your server receives its webhook and forwards it to the trigger's URL. Either way the run is the automation's, with its own `max_runs_per_hour` cap, and its pull request is read from the session.

## Why run it on Rush?

The fix is a name table; the proof is a running service. Showing that the endpoint answers again means installing spaCy and a language model, starting Flask, and posting real text, and a sandbox does that with nothing else on the machine, so the test shows what a fresh deployment would see rather than what a developer's laptop with three years of models happens to load.

The result is specific to this code, not to spaCy in general: it is the `lang` parameter on line 120 and the default on line 124 that turn a library change into a public 500, and the pull request says so with the lines. Other services built on the same pattern, a code search for `spacy.load(` finds them, get the same request as separate runs, each with its own sandbox and record.

## Frequently asked questions

### Why does spacy download en work but spacy.load('en') fail?

`spacy download en` prints a deprecation warning and installs `en_core_web_sm`, the package the shortcut used to point at. `spacy.load` no longer follows shortcuts, so loading `en` raises E941 while loading `en_core_web_sm` works. The agent changes the load, not just the download.

### Where does the mapping of codes to models come from?

From the installed spaCy package: its `OLD_MODEL_SHORTCUTS` table maps `en` to `en_core_web_sm`, `xx` to `xx_ent_wiki_sm` and the other two-letter codes to their `_core_news_sm` packages. The agent reads it from the package rather than hard-coding names from memory.

### Can I pin spacy below 3 instead?

A pin keeps the shortcuts, at the cost of staying on a line that the current models are not built for. The port is a few lines in one handler plus two documentation commands, and the pull request includes the pin bound in the other direction so the install and the docs agree.

### Does the agent need polyglot and the other libraries?

No. The handlers import their libraries lazily and `/status` lists what is missing, so the agent installs spaCy alone, starts the app and tests the one endpoint. The rest of the stack is left to the image build.

### What happens when a caller sends an unknown lang?

Today it raises inside `spacy.load` and the caller gets a 500. The fix answers a JSON error with the codes the service knows, which the test covers with a made-up code.

## More jobs like this: Fix a bug from an alert

- [Fix "AttributeError: module 'ssl' has no attribute 'wrap_socket'" on Python 3.12](https://getrush.ai/run/fix-ssl-wrap-socket-attribute-error/ssl/)
- [Fix "AttributeError: module 'streamlit' has no attribute 'beta_columns'" and the beta_expander Rename](https://getrush.ai/run/fix-streamlit-beta-columns-attribute-error/streamlit/)
- [Fix "AttributeError: module 'streamlit' has no attribute 'experimental_rerun'"](https://getrush.ai/run/fix-streamlit-experimental-rerun-attribute-error/streamlit/)
- [Fix "strings.Title Has Been Deprecated" (SA1019) in a Go CLI](https://getrush.ai/run/fix-strings-title-is-deprecated/strings/)
- [Fix "'Switch' is not exported from 'react-router-dom'" after upgrading to React Router 6](https://getrush.ai/run/fix-switch-is-not-exported-from-react-router-dom/react-router/)
- [Fix "It looks like you're trying to use `tailwindcss` directly as a PostCSS plugin" after Tailwind CSS 4](https://getrush.ai/run/fix-tailwindcss-directly-as-postcss-plugin/tailwind/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
