When I run my python code, I meet an import error. The error message is ImportError: No module named setuptools. The reason for this error is because we do not install the python setuptools module, so to fix it, we just need to install the python setuptools module.
1. Install Python setuptools Module.
- First, we should download the python
setuptools
package. Open a terminal and run the belowwget
command to download the pythonsetuptools
module.l# wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
- Run
tar
command to unpack the downloaded package.# unpack setuptools package. # tar zxvf setuptools-0.6c11.tar.gz # goto unpacked directory # cd setuptools-0.6c1
- Compile
setuptools
with python build command.# python setup.py build
- Install
setuptools
package use pythoninstall
command. After you complete the installation, the error will be fixed.# python setup.py install
2. Question & Answer.
2.1 How to fix the python no module named ‘setuptools’ error on macOS.
- My python is installed o macOS X, the python version is 3.6. I want to install the python library
pysparse
on it, but when I run the commandpython setup.py install
to install it, it always returns the error message ImportError: No module named ‘setuptools’. How can I fix this error? Thanks. - First, you can run the command
python -m pip --version
to check whether you have installed pip on your macOS or not.$ python -m pip --version pip 21.0.1 from /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip (python 3.7)
If you installed pip in your macOS, you can run the command
pip install setuptools
to install thesetuptools
. If your macOS has not installed pip, you can follow the below steps to install it.
Run the below command in a terminal to download theget-pip.py
file.curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Then run the command
python get-pip.py
for Unix/macOS, orpy get-pip.py
for Windows to install the pip.