Python 3: Importerror "No Module Named Setuptools"

Python 3: ImportError No Module named Setuptools

Your setup.py file needs setuptools. Some Python packages used to use distutils for distribution, but most now use setuptools, a more complete package. Here is a question about the differences between them.

To install setuptools on Debian:

sudo apt-get install python3-setuptools

For an older version of Python (Python 2.x):

sudo apt-get install python-setuptools

ModuleNotFoundError: No module named 'setuptools._distutils'

I have resolved it with the below option.

Linux

export SETUPTOOLS_USE_DISTUTILS=stdlib

Windows

set SETUPTOOLS_USE_DISTUTILS=stdlib

After that, I have executed the pip install command.

pip install django_microsoft_auth

This is the bug in setuptools. See ModuleNotFoundError: No module named 'setuptools._distutils' #2353.

No module named setuptools error, despite it being installed

The setup.sh script is executed in a new shell environment, so it is probably using your default Python interpreter instead of the Python interpreter from your virtual Python environment. And apparently, setuptools is not installed for the default interpeter (NB: that would possibly require root access).

If the shell script contains only the four lines you mentioned above, you could simply "source" the script by entering either

source setup.sh

or

. setup.sh

Note that this solution might not work if the script contains other code as well.

By "sourcing" the script, all commands are executed in the same shell (i.e. without starting a new shell), so this makes sure the Python interpreter from your virtual environment is used.

Getting ModuleNotFoundError: No module named 'setuptools.version' while having setuptools already installed

Apparently, after looking up the directory:

"C:\Users\user\AppData\Roaming\Python\Python38\site-packages\setuptools"

I found out that it does not contain the module "version.py" which was probably used to check if 'setuptools' was installed.

So I tried to copy the contents of "C:\Program Files\Python38\Lib\site-packages\setuptools"
into the matching folder mentioned above and now the problem is solved, I even tried to restart my PC to see if the fix was temporary - Gladly, it wasn't.

Although I'm not sure why the problem occurred to begin with, it seems to be solved now.

The output after the fix:
fixed output

No module named 'setuptools', even though the module is installed

It should be installed system-wide. If you are using Ubuntu/Debian:

apt-get install -y python-setuptools

If you are on Windows, see this answer to install setup tools.



Related Topics



Leave a reply



Submit