# Fix "AttributeError: module 'ast' has no attribute 'Str'" on Python 3.14

Yes. An agent replaces ast.Str and its removed siblings with ast.Constant, keeps older Pythons parsing correctly, and builds the package from source to prove it.

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

## What the agent does

Python 3.14 removed `ast.Str`, along with `ast.Num`, `ast.Bytes`, `ast.NameConstant` and `ast.Ellipsis`. String and number literals have been `ast.Constant` nodes since Python 3.8, and the old names were kept as deprecated aliases until now. Code that inspects syntax trees breaks, and the most common place to find such code is not a linter or a code generator. It is `setup.py`. Many projects read their version by parsing `__init__.py` instead of importing it, and html5lib/html5lib-python is one: lines 88 to 97 of its `setup.py` parse `html5lib/__init__.py`, look for an assignment to `__version__`, and accept it only when `isinstance(a.value, ast.Str)`, then read `a.value.s`. On 3.14 that test raises the error in the title, so the failure happens while building the package, before any of the library is imported.

The agent reproduces it by running the build, and the first thing it finds is a different error. The repository has no `pyproject.toml`, so a build uses whatever setuptools is current, and line 9 of `setup.py` is `from pkg_resources import parse_version`. With setuptools 84 that import fails with `No module named 'pkg_resources'` on every Python version. Pinning setuptools 80 gets past it, and then the two interpreters part ways: on 3.12, `python setup.py --version` prints `1.2.dev0`, and on 3.14 it stops at line 96 with the `ast.Str` error. The agent keeps all three outputs. The order matters to anyone searching for the message: which of the two errors you meet depends on the setuptools your build picked up.

For the title's error, the replacement is `ast.Constant` with a check that the value is a string, reading `.value` instead of `.s`. The agent does not stop at the obvious edit, because the same file declares `python_requires` from 2.7 upward. On Python 3.7 and earlier the parser still produces `Str` nodes that are not instances of `ast.Constant`, so a check for `Constant` alone would find no version there, and the build would carry on without one. The agent either accepts both node types, looking up the old name with `getattr` so that its absence is harmless, or raises the minimum Python and says that it did. It tests the result where it can: the patched file reports `1.2.dev0` on 3.8, 3.12 and 3.14.

For the first error, it reads what `pkg_resources` was doing. In `setup.py` it compares the setuptools version against 18.5 to work around a marker bug in releases that old, a block that can go. `html5lib/tests/conftest.py` uses it as well, to parse requirement lines and look up installed packages, which is the job of `packaging` and `importlib.metadata` today. The agent proposes these as separate commits, since a maintainer may take the `ast` fix at once and want to discuss the rest. It also notes that the CI matrix in `.github/workflows/python-tox.yml` stops at 3.12 and adds the newer interpreters, so the workflow would catch the next removal.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "Building or installing this project from source on Python 3.14 fails with \"AttributeError: module 'ast' has no attribute 'Str'\". Reproduce it first: on Python 3.14 run the project's build (python -m build, pip install from the checkout, or python setup.py --version) and save the full error. If a different error comes first, such as a missing pkg_resources module from a current setuptools, record it, say which tool version causes it, and get past it in a throwaway environment so you can reach the ast error too. Then find every use of the removed ast classes (ast.Str, ast.Num, ast.Bytes, ast.NameConstant, ast.Ellipsis) and of the .s and .n attributes on constant nodes, in setup.py, the package, tools and tests. Replace each with ast.Constant and a check on the type of .value. Read which Python versions the project claims to support; on interpreters before 3.8 literals are not ast.Constant nodes, so either keep those versions working and show it, or raise the minimum version and say so. Show that the build reports the same version string before and after on an older Python and on 3.14. Fix the earlier blocker in a separate commit, replacing pkg_resources with packaging or importlib.metadata where it is still needed and deleting workarounds for tool versions nobody can install. Add the newest Python versions to the CI matrix. Open a pull request with every error you met in the order you met it, the version output on each interpreter, the test results, and what you left alone.",
  "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 with two or three commits. The first changes the version lookup in `setup.py` and is a handful of lines. The second removes the `pkg_resources` imports and the workaround built on them, and updates `conftest.py`. The third extends the workflow matrix. The description lists the errors in the order a builder meets them, each with the interpreter and setuptools version that produced it, and then the version string printed by the build on each interpreter after the change.

A reviewer checks the oldest claimed interpreter first: the description must show a version string there, or state that the minimum was raised. They check that the reported version is unchanged, since a lookup that silently returns nothing still builds. They can merge the first commit alone. If the test suite cannot run on the newest interpreter for reasons outside these changes, such as pinned test tools, the agent reports the failing step and does not present the suite as passing.

## Run it on every Monday morning

Build breakage of this kind comes from outside the repository: a new interpreter or a new setuptools release, on a day when nobody pushed a commit. A schedule finds it before a user does. Add an automation on the Project with a `schedule` trigger, a weekly `cron` and your `timezone`, and a prompt that builds the project from source on the newest Python with current build tools and fixes what fails, using the request above as the model.

On most Mondays the build passes and the run reports that and opens nothing. For a set of libraries, give each Project the same automation; its max runs per hour bounds what a bad week can start. If you want the run only when something breaks, use a `github` trigger on `workflow_run.failure` instead, and the failed run is added after the prompt as event text.

## Why run it on Rush?

The failure depends on two versions at once, the interpreter and the build tool, and a developer's machine has one fixed pair. The agent can set up each combination in its sandbox: current setuptools, an older one, Python 3.8, 3.12 and 3.14. That is how it learns that the error in the title is the second one a builder meets today. The output of every build attempt is kept with the session, so the ordering in the pull request can be checked.

Source builds are also what downstream packagers do. A library whose wheel on the package index installs everywhere can still be broken for a distribution that builds from the tarball, or for anyone installing from a git URL. A weekly run that builds from the checkout sees what they see.

## Frequently asked questions

### What replaces ast.Str, ast.Num and ast.Bytes?

`ast.Constant`. Check the node with `isinstance(node, ast.Constant)` and then the type of `node.value`, for example `isinstance(node.value, str)`. Read `node.value` where old code read `node.s` or `node.n`; those attributes are gone in 3.14 as well.

### I only ran pip install and got this error. Why is my own code not in the traceback?

Because the failing file is a dependency's `setup.py`, run by pip to build it from source. Check whether the dependency has a newer release or a prebuilt wheel for your interpreter. If neither exists, the fix belongs upstream, and the agent can prepare it against a fork you own.

### Did Python warn about this?

Yes. On 3.12, touching `ast.Str` prints `DeprecationWarning: ast.Str is deprecated and will be removed in Python 3.14; use ast.Constant instead`. pip hides a build's output unless the build fails, which is why few people saw it.

### Is there a way to avoid parsing the version at all?

Yes. Setuptools can read it declaratively, with `version = attr: package.__version__` in `setup.cfg` or the dynamic version table in `pyproject.toml`, and it finds simple assignments without importing the package. The agent offers that as an alternative when the project's supported setuptools range allows it.

## More jobs like this: Upgrade dependencies weekly

- [Fix "Bad Argument Type. Starting with v5, Only the Object Form Is Allowed" After a TanStack Query Upgrade](https://getrush.ai/run/fix-bad-argument-type-only-object-form-allowed/tanstack-query/)
- [Fix the Browserslist caniuse-lite Is Outdated Warning](https://getrush.ai/run/fix-caniuse-lite-is-outdated-warning/browserslist/)
- [Fix Cannot Find Module @babel/core After a babel-loader Upgrade](https://getrush.ai/run/fix-cannot-find-module-babel-core/babel-loader/)
- [Fix "Cannot Import Name 'Imputer' from 'sklearn.preprocessing'" After a scikit-learn Upgrade](https://getrush.ai/run/fix-cannot-import-name-imputer-from-sklearn-preprocessing/scikit-learn/)
- [Fix d3.event Is Undefined After Upgrading D3](https://getrush.ai/run/fix-d3-event-removed/d3/)
- [Fix "Support for defaultProps Will Be Removed from Function Components" After a React 18.3 Upgrade](https://getrush.ai/run/fix-defaultprops-will-be-removed-from-function-components-warning/react/)

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