Solving python setuptools Error while downloading the requirements using pip install (setup command: use_2to3 is invalid.)

Python setuptools Error while downloading the requirements using pip install (setup command: use_2to3 is invalid.) is an error which occurs when you install a package that requires use_2to3.

Today I will be explaining why this error is taking place and how to solve it.

Exploring the python setuptools Error while downloading the requirements using pip install (setup command: use_2to3 is invalid.)

This is an error which occurs when you install a package that requires use_2to3.

Please make sure the error message looks like the error message bellow after double checking. Do not mix between errors.

                                                                       #
error in mongoengine setup command: use_2to3 is invalid.
                                                                       #

Bellow is a number of tested methods that I have tried and that have worked for me.

Solution 1 : Downgrade or upgrade packages that use use_2to3

In most cases the error occurs when you directly install a package that requires use_2to3.

Sometimes it can happen if you try to install requirements.txt by using the command bellow for example.

                                                                       #
pip install -r  requirements.txt
                                                                       #

There are few options to solve this issue.

The first option is to Upgrade or Downgrade the package you were trying to install .

because some packages drop support for python 2 which causes the error we have here.

So, once you identify the package, just downgrade it or upgrade it depending on the case , you can even choose a specific version of the package like this.

                                                                       #
pip install <package-name>==<package-version>
                                                                       #

This error happens a lot with the MongoEngine for example and installing any version that came after version 0.20 , will solve the issue.

The second option is presented in the method bellow.

Solution 2 : Downgrade Setuptools or Do not use packages that use use_2to3

A great option is to NOT Use packages that use use_2to3 but it is not very practical of course, you cannot just ask developers to not use a package.

Another option for setuptools is to install a setuptool version inferior or equal to the 58 version of setuptools

                                                                       #
pip install setuptools==57.1.0
                                                                       #

Any version will do, you do not have to install version 57.1.0 this is just an example.

Even installing setuptools==58 will fix the issue for you

                                                                       #
pip install setuptools==58
                                                                       #

The error happens because setuptool versions that were released after setuptools 58 all do not support use_2to3 , hence the error.

I hope the fixes above fixed your problem, thanks for reading the whole thing, good luck with your python project.

Summing-up : 

That is it guys, this is the end of this article aka guide, I hope you found it useful in solving your problem, make sure to support our work on Kofi, you do not have to but hey you can donate to the team.

Thank you for reading my blog post to the end, If you want to learn more about the Python programming language, check out the official Python Documentation : https://docs.python.org/3/