# Fix "AttributeError: module 'emoji' has no attribute 'UNICODE_EMOJI'"

Yes. An agent finds every read of the dictionary emoji 2.0 removed, moves the code to EMOJI_DATA, and shows that the output on both versions is the same.

[Run this on Rush](https://cloud.getrush.ai/run/fix-module-emoji-has-no-attribute-unicode-emoji/emoji/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The `emoji` package dropped `UNICODE_EMOJI` in its 2.0.0 release, along with the per-language dictionaries nested under it, and replaced them with one `EMOJI_DATA` dictionary keyed by the emoji itself. Code written against 1.x reads `emoji.UNICODE_EMOJI` or `emoji.UNICODE_EMOJI["en"]` and stops with the AttributeError in the title the first time the package is installed without a pin. The 1.7.0 release carries both names, which is what makes a clean migration possible before the pin moves.

In a text-processing library like aub-mind/arabert, `requirements.txt` and `setup.py` both pin `emoji==1.4.2`, and `preprocess.py` is where the dependency lives. `ArabertPreprocessor.__init__` imports `emoji` only when `keep_emojis` is on, which it is by default for the models listed in `TWEET_MODELS`, and on line 317 it builds a character class from `"".join(list(self.emoji.UNICODE_EMOJI["en"].keys()))` to decide which characters survive cleaning. Three more sites, on lines 512, 587 and 708, test `if word in list(self.emoji.UNICODE_EMOJI["en"].keys())` inside the Farasa segmentation branches, rebuilding a list of thousands of keys for every word. Constructing `ArabertPreprocessor(model_name="bert-base-arabertv02-twitter")` with the current emoji release raises the error from line 317 before any text is processed.

The agent reproduces that in a fresh virtual environment, then reads what the two releases expose. On 1.4.2, `UNICODE_EMOJI` is a dictionary of six language codes and its `en` table holds 3,521 entries. On the current 2.x release there is no `UNICODE_EMOJI`; `EMOJI_DATA` holds 5,244 entries, each emoji mapping to its English name, status and the Unicode version it arrived in, and the module also offers `is_emoji`, `emoji_list` and `replace_emoji`. The difference in size matters: the newer table knows emoji added to Unicode after 2021, so cleaning with it keeps characters the old table threw away. The agent writes a small comparison script before touching the code, runs the preprocessor on a handful of Arabic and English strings with emoji, flags and a family sequence on 1.4.2, and records the output.

Then it changes the four sites. The regex on line 317 becomes a join over `EMOJI_DATA.keys()`, which keeps the existing character-class approach and its quirk that multi-code-point sequences such as flags are split into their parts. The three membership tests become `self.emoji.is_emoji(word)`, which answers the same question without building a list per word. The pin moves to a range that includes the new name, `emoji>=1.7`, in both files. The agent runs the comparison again on the new release: the cleaned strings match the recorded ones character for character, and the only new behaviour is that an emoji from a newer Unicode release, which 1.4.2 stripped as unknown, is now kept.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "This project fails with AttributeError: module 'emoji' has no attribute 'UNICODE_EMOJI' once emoji is installed without its pin. Reproduce it in a clean virtual environment with the current emoji release and quote the traceback. Find every read of emoji.UNICODE_EMOJI (and EMOJI_UNICODE, EMOJI_ALIAS_UNICODE or UNICODE_EMOJI_ALIAS if present) and say what each one is used for: building a regex, a membership test, or a lookup of a name. Install the pinned 1.x release in a second environment and write a comparison script that runs the affected functions on sample strings containing single emoji, flags, a family sequence with zero-width joiners, and an emoji added to Unicode after the pinned release; record the outputs. Port the code to the 2.x API: EMOJI_DATA for the table, is_emoji or emoji_list for membership tests, and a pin that admits the new name while the old one is still supported. Rerun the comparison on the new release and list every string whose output changed, with the reason. Do not vendor the old table and do not leave both names in the code. Open a pull request with the traceback, the two outputs side by side and the version pin change.",
  "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 edits the preprocessing module and the two pin files. The description opens with the traceback pointing at the regex line, states what the old and new tables contain, and lists the four sites with the form each took before and after. The comparison script and its two outputs sit below that as a table, one row per sample string, with a column for the 1.x result and one for the 2.x result.

Where the two columns differ, the row says why. On a project like this the only difference is an emoji that the pinned release did not know and the current one does, so the cleaned text keeps it. A reviewer who trains models on that cleaned text decides whether a character that used to vanish should now reach the tokenizer, and the pull request gives them the exact string to decide on.

The reviewer also checks the pin. A lower bound of 1.7 keeps older environments installable and a cap below 3.0 protects against the next rename; the description says which the agent chose and why, and notes that `setup.py` and `requirements.txt` must agree, since the package's users install from one and the repository's CI from the other.

## Run it on every install that resolves a newer emoji release

This error arrives on a rebuild, not on a commit: a Docker image is refreshed, a notebook environment is recreated, or someone removes a pin during an upgrade, and the import that worked for years raises on the next start. Add an automation to the Project with the prompt above and a `github` trigger on `workflow_run.failure`, so a CI job that installs the project and fails on this AttributeError starts a run with the failed workflow placed after the prompt as the event.

If the project has no CI, give the automation a `schedule` trigger instead and let the prompt install the project unpinned once a week in a fresh environment. A run that finds the import clean ends with a short note and no pull request; the first one that hits the rename opens the port. Set the automation's max runs per hour low, since one broken dependency can fail several workflows in the same push.

## Why run it on Rush?

The fix is four lines, and the risk is in none of them. What matters is whether text cleaned by the new table matches text cleaned by the old one, and that can only be seen by running the same inputs through both releases, which means two environments and a diff. A Rush sandbox holds both side by side, and the session keeps each install, the comparison script and both outputs, so the pull request shows the evidence rather than asserting it.

Libraries like this tend to have no test suite for their preprocessing, and the people who depend on them notice a change only when a model's numbers move. Having the run write the comparison first turns a silent behaviour change into a table a reviewer can read, and a team with several projects that still pin emoji 1.x starts one run per repository with the same request and reviews the ports as they arrive.

## Frequently asked questions

### Can I just pin emoji below 2.0?

Yes, and it is the one-line fix for an environment that must not change today. The 1.x line stopped at 1.7.0 in March 2022, so the pin freezes the emoji table at that point and every emoji added to Unicode since then passes through code that was written to strip emoji. The agent reports the pin as an option and ports the code so the pin can go.

### Is EMOJI_DATA a drop-in for UNICODE_EMOJI['en']?

For the keys, yes: both are keyed by the emoji string, so a regex or a membership test over the keys ports directly. The values differ: the old table mapped to a name like `:grinning_face:`, while the new one maps to a dictionary with the English name under `en`, plus a status and a Unicode version. Code that read the name needs the extra key.

### What about the other dictionaries, like EMOJI_UNICODE?

They were removed in the same release. A name lookup becomes `emoji.emojize` with the colon-wrapped name, and the reverse becomes `emoji.demojize`. The prompt asks the agent to find those reads too, so a module that used more than one table is ported in one pull request.

### Why do flags come out as separate characters?

Because the original code joins the table's keys into a regex character class, which treats each code point on its own. A flag is two regional-indicator code points, so both are kept but the space the cleaner inserts between tokens separates them. That behaviour is identical on both releases, and the agent keeps it rather than changing the cleaning rules in a dependency fix.

### Does this change what a model trained on the old output sees?

Only for emoji the pinned release did not know. The comparison table lists each such string, and the pull request leaves the decision to whoever owns the model: keep the new behaviour, or add those characters to the rejected set explicitly.

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

- [Fix Moment's "Value Provided Is Not in a Recognized RFC2822 or ISO Format" Warning](https://getrush.ai/run/fix-moment-value-provided-is-not-in-a-recognized-format-warning/moment/)
- [Fix "Model.find() no longer accepts a callback" After a Mongoose Upgrade](https://getrush.ai/run/fix-mongoose-callback-error/mongoose/)
- [Fix "DeprecationWarning: Mongoose: the `strictQuery` option will be switched back to `false` by default in Mongoose 7"](https://getrush.ai/run/fix-mongoose-strictquery-deprecation-warning/mongoose/)
- [Fix "MongoParseError: options usecreateindex, usefindandmodify are not supported" in Mongoose 6 and Later](https://getrush.ai/run/fix-mongoose-usecreateindex-not-supported/mongoose/)
- [Fix Alembic Multiple Heads After a Merge](https://getrush.ai/run/fix-multiple-heads/alembic/)
- [Fix "OSError: mysql_config not found" When Installing a Flask App's Requirements](https://getrush.ai/run/fix-mysql-config-not-found/mysqlclient/)

## 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/)
