Error in X setup command: use_2to3 is invalid [Solved]

avatar
Borislav Hadzhiev

Last updated: Apr 10, 2024
3 min

banner

# Error in X setup command: use_2to3 is invalid [Solved]

The "error in X setup command: use_2to3 is invalid" error occurs because setuptools has removed support for 2to3 during builds.

To solve the error, pin your setuptools version to 57.5.0 before installing the package.

error in package setup command use2to3 is invalid

shell
ERROR: Command errored out with exit status 1: error in package setup command: use_2to3 is invalid. ---------------------------------------- WARNING: Discarding package. Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output. ERROR: Could not find a version that satisfies the requirement ERROR: No matching distribution found for package

There has been a breaking change in setuptools version 58.0.0.

The setuptools package has removed support for 2to3 during builds.

You can solve the error by pinning your setuptools version to the last version before 58.0.0.

# Pin your setuptools version to <58.0

Open your terminal and run the following command.

shell
pip install "setuptools<58.0" pip3 install "setuptools<58.0" python -m pip install "setuptools<58.0" python3 -m pip install "setuptools<58.0" py -m pip install "setuptools<58.0"

pin setuptools version

Alternatively, you can avoid using packages that have use_2to3 in their setup parameters.

# Rerun the pip install command after pinning setuptools

Try to rerun your pip install command after pinning your setuptools version.

shell
pip install mongoengine pip3 install mongoengine python -m pip install mongoengine python3 -m pip install mongoengine py -m pip install mongoengine
Make sure to replace the mongoengine package with the name of the package you're trying to install.

# Trying to install the latest version of the package

Alternatively, you can try to install the latest version of the package.

shell
pip install mongoengine --upgrade pip3 install mongoengine --upgrade python -m pip install mongoengine --upgrade python3 -m pip install mongoengine --upgrade py -m pip install mongoengine --upgrade

install latest version of package

Make sure to replace mongoengine with the name of the package you're trying to install.

# Trying to install a prerelease version of the package

If that didn't help, try running the pip install command with the --pre option.

shell
pip install mongoengine --pre pip3 install mongoengine --pre python -m pip install mongoengine --pre python3 -m pip install mongoengine --pre py -m pip install mongoengine --pre

install prerelease version of package

The --pre option makes it so pip includes pre-release and development versions of the package. By default, pip only finds stable versions.

The latest version of the package might not have use_2to3 in its setup parameters.

# Update your requirements.txt file

If you use a requirements.txt file, you can update it with the following command.

shell
pip freeze > requirements.txt

The command will update the contents of your requirements.txt file, so the next time you run the pip install -r requirements.txt, your project will be in a working state.

# Upgrade your version of pip

If the error persists, try upgrading your version of pip as well.

shell
pip install --upgrade pip "setuptools<58.0" pip3 install --upgrade pip "setuptools<58.0" python -m pip install --upgrade pip "setuptools<58.0" python3 -m pip install --upgrade pip "setuptools<58.0" py -m pip install --upgrade pip "setuptools<58.0"

upgrade pip while pinning setuptools

Try to rerun your pip install command after upgrading your version of pip.

shell
pip install mongoengine pip3 install mongoengine python -m pip install mongoengine python3 -m pip install mongoengine py -m pip install mongoengine

Make sure to replace the mongoengine package with the name of the package you're trying to install.

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.