Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

pip install fails with 'use_2to3 is invalid' for an old package

Errorerror in anyjson setup command: use_2to3 is invalid.

Short answer

Setuptools 58 removed the use_2to3 option, and an old package that still sets it fails to build. The official advice is to port the package or pin an older setuptools. To install it anyway, install a setuptools below 58 and tell pip not to use build isolation.

  • Applies to pip 24, setuptools below 58, Python 3.10-3.12
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    See which setuptools version pip would use and whether the package is pulled in by something you can upgrade.

    pip --version
    pip show setuptools
    pip install anyjson 2>&1 | tail -n 15
  2. 2Match what you see, then jump to its fix

    1. 1use_2to3 is invalidThe package asks for 2to3 conversion and setuptools no longer supports itFix
    2. 2You already pinned setuptools in your environment, but the error remainspip's isolated build environment fetches a new setuptools every timeFix

What does the error look like?

  • error in anyjson setup command: use_2to3 is invalid.
  • ERROR: Failed building wheel for anyjson

Cause 1 of 2

The package asks for 2to3 conversion and setuptools no longer supports it

1Check

The setuptools changelog says v58.0.0 removed 2to3 support during builds, and later 58.0.x releases fail fast when use_2to3 is supplied (not when it is set to a false value).

pip download anyjson --no-deps --no-binary :all: -d /tmp/pkg && grep -R use_2to3 /tmp/pkg

2Fix

Preferred: upgrade the package that depends on it, or a maintained replacement. If you must keep it, pin setuptools below 58 as the changelog advises, and build without isolation so pip uses that setuptools.

pip install "setuptools<58" wheel
pip install --no-build-isolation anyjson

3Verify

The package installs.

pip show anyjson

Confirmed by setuptools.pypa.io

Did this fix it?

Cause 2 of 2

pip's isolated build environment fetches a new setuptools every time

1Check

pip builds source packages in an isolated environment by default. --no-build-isolation turns that off, and the build dependencies must then be present in your environment.

pip config list; env | grep PIP_

2Fix

Either use --no-build-isolation as above, or keep isolation and give pip a constraints file for build dependencies.

echo "setuptools<58" > build-constraints.txt
pip install --build-constraint build-constraints.txt anyjson

3Verify

pip builds the wheel with the pinned setuptools and the install completes.

pip show anyjson

Confirmed by pip.pypa.io

Did this fix it?

How do I stop it coming back?

  • Replace unmaintained dependencies instead of pinning old build tools forever.
  • Pin setuptools in the Dockerfile or constraints file, so the build does not change when a new release appears.
  • Check how old a package is before you add it to requirements.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.