All jobs

Fix "OSError: mysql_config not found" When Installing a Flask App's Requirements

Yes. The agent drops the mysqlclient pin nothing imports, swaps source-only psycopg2 for its wheel, proves a clean install, and opens a pull request.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

OSError: mysql_config not found is what pip install mysqlclient prints on a machine without the MySQL client headers: the package builds a C extension and its setup_posix.py shells out to mysql_config for flags. Newer mysqlclient releases say it differently, Exception: Can not find valid pkg-config name. Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually, but the cause is the same. The run starts with the failing install log, and the agent clones the repository into its own cloud sandbox.

In a Flask app like vigneshshettyin/Flask-Generate-Certificate, requirements.txt has fifty-two pinned lines including mysqlclient==2.0.3 and psycopg2==2.9.1. config.py reads DATABASE_URL through python-decouple and rewrites a postgres:// scheme to postgresql://, .env.sample sets DATABASE_URL=sqlite:///cgv.db, and no file in the repository imports MySQLdb or builds a mysql:// URL, so the MySQL driver is a pin nothing uses. docs/INSTALLATION.md step 4 is pip3 install -r requirements.txt inside a virtualenv, the Dockerfile runs the same line on python:3, and the Procfile starts gunicorn app:app.

The agent reproduces the install in a clean virtualenv: pip stops at mysqlclient with the OSError from setup_posix.py. With that line removed it stops again at psycopg2 with Error: pg_config executable not found, because psycopg2 ships source only and psycopg2-binary is the wheel. Postgres is a real target here, the postgres:// rewrite in config.py exists for a hosted database, so that driver stays, as the wheel.

The pull request drops mysqlclient==2.0.3 and replaces psycopg2==2.9.1 with psycopg2-binary==2.9.10. The install then completes, and the agent imports the app with a .env copied from .env.sample to prove the modules load. One more thing surfaces there: razorpay==1.3.0 imports pkg_resources, which setuptools 81 removed, so the agent adds a setuptools<81 pin and names it as a separate, older-package issue for the maintainer. It also updates docs/INSTALLATION.md so no system package is implied.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "pip install -r requirements.txt fails with OSError: mysql_config not found. Check whether the app imports MySQLdb or uses a mysql:// URL anywhere; if not, remove the mysqlclient pin. Then continue the install in a clean virtualenv, fix any other package that needs system headers, prefer a wheel over installing apt packages, confirm the app imports with the sample .env, update the install docs, and open a pull request that quotes each error and says why each line changed.",
  "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

What comes back is a pull request that edits requirements.txt and docs/INSTALLATION.md. Its description quotes the mysql_config error, the pg_config error that follows it, and the pkg_resources import error from razorpay, and shows the clean install completing and import app succeeding with the sample environment.

A reviewer checks that no code path needs the MySQL driver (the grep result is in the description), that psycopg2-binary is acceptable for the deployment (the psycopg2 project recommends the source build for production, and the pull request says that), and that the setuptools pin is marked as temporary until razorpay is upgraded.

The Docker build on python:3 is unchanged by this pull request beyond the shorter requirements file; the session keeps the install logs for anyone who wants to see the three failures in order.

Run it on every issue labelled install

Create an automation in the Project with this prompt and a github trigger on issues.labeled with the label install. When a contributor opens an issue with their failed pip install output and a maintainer adds the label, the run starts with the issue after the prompt, reproduces the install in a clean virtualenv, and opens a pull request or answers on the issue with what it found.

Only labels added by someone who can write to the repository fire the trigger, so a drive-by label starts nothing. The automation's max_runs_per_hour caps a burst of issues.

The use case this job follows, with its automation and trigger: Fix a bug from an alert.

Why run it on Rush?

Native-extension installs fail differently on every machine, depending on which headers happen to be present. A Rush run installs in a sandbox with none of them, which is the contributor's laptop at its worst, keeps each failure in order, and shows the install finishing, so the pull request carries the proof instead of a claim that it works somewhere.

Long pinned requirement files collect packages that nothing imports. The run greps the code for each native dependency's import before touching the pin, writes the grep result into the description, and can do the same for several repositories at once, one run and one pull request each.

Frequently asked questions

Should I install default-libmysqlclient-dev instead of removing the pin?

Only if the app uses MySQL. Here no file imports MySQLdb and the database URL is Postgres or SQLite, so the pin is dead weight that makes every install need a compiler and headers. The pull request removes it and says where it looked.

Is psycopg2-binary safe for production?

The psycopg2 project recommends building from source in production and the wheel for development. The pull request uses the wheel so a contributor's install works without libpq-dev, and says that a production image can keep psycopg2 with the headers installed in its Dockerfile.

Why pin setuptools?

razorpay==1.3.0 imports pkg_resources, which setuptools removed in release 81, so the app fails to import on a fresh virtualenv even after the install succeeds. The pin is the smallest fix; upgrading razorpay is the real one, and the description says so.

Will this change the Docker image?

The Dockerfile runs the same pip3 install -r requirements.txt, so it installs two packages fewer and builds no C extension for MySQL. The agent does not change the base image or add apt packages, because the app no longer needs them.

More jobs like this: Fix a bug from an alert

Keep reading