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:
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
Scraping Dynamic Content Using Python-Scrapy
Converting a String to a List of Words
What Are the Most Common Python Docstring Formats
Including Non-Python Files with Setup.Py
Elegant Python Function to Convert Camelcase to Snake_Case
How to Check a String for Specific Characters
Insert an Element at a Specific Index in a List and Return the Updated List
Execute Multiple Commands in Paramiko So That Commands Are Affected by Their Predecessors
How to Convert This List of Dictionaries to a CSV File
Extract Images from PDF Without Resampling, in Python
Break // in X Axis of Matplotlib
What Is the Easiest Way to Remove All Packages Installed by Pip
Multiprocessing: Sharing a Large Read-Only Object Between Processes
Why Are Empty Strings Returned in Split() Results
Traverse a List in Reverse Order in Python