PyPI Upload Errors: The Questions Everyone Eventually Asks

Python packaging has improved enormously since pyproject.toml became the standard place for project metadata, but the final step, uploading with Twine or a CI action, still trips people up. These are the questions that recur in Python packaging forums and issue trackers, rewritten in our own words, with the fixes that tend to work.

Why does PyPI say the file already exists?

PyPI never lets you upload a distribution file with the same filename twice, even after you delete the release. Filenames are derived from the project name, version and tags, so in practice this means you cannot reuse a version number. Bump the version in pyproject.toml, rebuild and upload again. If you are experimenting, use TestPyPI, which is a separate instance meant for exactly this, and remember that it has its own accounts and tokens.

Why was my upload rejected because of the description?

PyPI renders your long description on the project page and refuses uploads it cannot render. The usual cause is a Markdown README declared as reStructuredText, or vice versa. With modern metadata, point at the file and the content type is inferred from the extension:

[project]
name = "tidy-dates"
version = "0.3.0"
readme = "README.md"
requires-python = ">=3.9"
license = "MIT"

Running twine check dist/* before uploading catches rendering problems locally.

What is wrong with my classifiers?

Trove classifiers must match the official list exactly, character for character. A typo or an invented classifier causes a rejection. Copy them from the classifiers page on PyPI rather than typing them. A handy trick: the special classifier Private :: Do Not Upload makes PyPI reject the package on purpose, which is useful for internal projects that should never be published by accident.

The name I want is free, so why can I not use it?

PyPI normalises names according to the rules in the Python Packaging User Guide: case is ignored and runs of hyphens, underscores and dots are treated as equivalent. So Tidy_Dates and tidy-dates are the same project. Some names are also blocked or reserved. If the name you want is held by an abandoned project, PEP 541 describes the process for requesting a transfer, and it is deliberately conservative.

Do I still need an API token?

For uploads from a laptop, yes: PyPI requires API tokens or Trusted Publishing rather than a username and password, and accounts must use two-factor authentication. Scope tokens to a single project once it exists. For CI, Trusted Publishing lets a supported workflow exchange a short-lived identity token for upload rights, so no secret sits in your repository settings at all. Our Trusted Publishing setup guide walks through it.

A short checklist distilled from these threads

  1. Build both an sdist and a wheel with python -m build.
  2. Inspect the wheel contents; it is a zip file, so any archive tool will open it.
  3. Run twine check dist/*.
  4. Upload to TestPyPI first for a brand-new project.
  5. Install from TestPyPI in a clean virtual environment and import the package.
  6. Only then upload to the real index.

Related pages