Last updated: Apr 8, 2024
Reading timeยท7 min
The Python "ModuleNotFoundError: No module named 'setuptools'" occurs when
setuptools
is not installed in our Python environment.
To solve the error, install the module by running the
python -m pip install --upgrade setuptools
.
Open your terminal and run the following command to install setuptools.
pip install --upgrade setuptools # ๐๏ธ For Python 3 pip3 install --upgrade setuptools # ๐๏ธ If you don't have pip in PATH python -m pip install --upgrade setuptools python3 -m pip install --upgrade setuptools # ๐๏ธ Windows py -m pip install --upgrade setuptools
If the error is not resolved, try to uninstall setuptools
and then install the
module.
# ๐๏ธ Uninstall setuptools pip uninstall setuptools pip3 uninstall setuptools # ๐๏ธ Install setuptools pip install setuptools pip3 install setuptools
You can also try to upgrade the version of the setuptools package.
pip install --upgrade pip setuptools wheel # ๐๏ธ For Python 3 pip3 install --upgrade pip setuptools wheel python -m pip install --upgrade pip setuptools wheel python3 -m pip install --upgrade pip setuptools wheel # ๐๏ธ Windows py -m pip install --upgrade pip setuptools wheel
Alternatively, you can use the official get-pip script to install setuptools.
Download the script from https://bootstrap.pypa.io/get-pip.py by clicking on the link, right-clicking and selecting "Save as" in your browser.
Open your terminal in the location where the get-pip.py
file is downloaded and
run the following command.
# ๐๏ธ On Linux or MacOS python get-pip.py # ๐๏ธ Using python 3 python3 get-pip.py # ๐๏ธ On Windows py get-pip.py
The get-pip.py
script installs or upgrades pip
and installs setuptools
and
wheel
if they aren't installed already.
Alternatively, you can create a virtual environment. The venv
module is
available by default in Python 3.3 and later, and installs pip
and
setuptools
into the created virtual environment.
# ๐๏ธ Use the correct version of Python when creating VENV python3 -m venv venv # ๐๏ธ Activate on Unix or MacOS source venv/bin/activate # ๐๏ธ Activate on Windows venv\Scripts\activate # ๐๏ธ Install the modules in your requirements.txt file # (if you have one) pip install -r requirements.txt
If the python3 -m venv venv
command doesn't work, try the following 2
commands:
python -m venv venv
py -m venv venv
Your virtual environment will use the version of Python that was used to create it.
The setuptools
module is guaranteed to be installed in the virtual
environment.
The Python "ModuleNotFoundError: No module named 'setuptools_rust'" occurs
when we have an outdated version of pip
or forget to install the
setuptools_rust
package.
To solve the error, upgrade pip
and install setuptools_rust
.
pip
version is up to date. Here are the commands for upgrading pip
on all operating systems.Which command works depends on your operating system and your version of Python.
# ๐๏ธ If you have pip already installed pip install --upgrade pip # ๐๏ธ If your pip is aliased as pip3 (Python 3) pip3 install --upgrade pip # ๐๏ธ If you don't have pip in your PATH environment variable python -m pip install --upgrade pip # ๐๏ธ If you don't have pip in your PATH environment variable python3 -m pip install --upgrade pip # ๐๏ธ If you have easy_install easy_install --upgrade pip # ๐๏ธ If you get a permissions error sudo easy_install --upgrade pip # ๐๏ธ If you get a permissions error when upgrading pip pip install --upgrade pip --user # ๐๏ธ Upgrade pip scoped to the current user (if you get a permissions error) python -m pip install --user --upgrade pip python3 -m pip install --user --upgrade pip # ๐๏ธ Installing directly from get-pip.py (MacOS and Linux) curl https://bootstrap.pypa.io/get-pip.py | python # ๐๏ธ If you get permissions issues curl https://bootstrap.pypa.io/get-pip.py | sudo python # ๐๏ธ Alternative for Ubuntu/Debian sudo apt-get update && apt-get upgrade python-pip # ๐๏ธ Alternative for Red Hat / CentOS / Fedora sudo yum install epel-release sudo yum install python-pip sudo yum update python-pip
If you get the error "ModuleNotFoundError: No module named 'pip' in Python", check out my other article:
Now that your pip
version is up to date, install
setuptools-rust.
# ๐๏ธ In a virtual environment or using Python 2 pip install setuptools-rust # ๐๏ธ For Python 3 (could also be pip3.10 depending on your version) pip3 install setuptools-rust # ๐๏ธ If you get a permissions error sudo pip3 install setuptools-rust pip install setuptools-rust --user # ๐๏ธ If you don't have pip in your PATH environment variable python -m pip install setuptools-rust # ๐๏ธ For Python 3 (could also be pip3.10 depending on your version) python3 -m pip install setuptools-rust # ๐๏ธ Using py alias (Windows) py -m pip install setuptools-rust # ๐๏ธ For Anaconda conda install -c conda-forge setuptools-rust # ๐๏ธ For Jupyter Notebook !pip install setuptools-rust
If the error is not resolved, try installing setuptools
as well.
Open your terminal and run the following command to install setuptools
.
# ๐๏ธ for Linux or MacOS python3 -m pip install --upgrade pip setuptools wheel # ๐๏ธ Windows py -m pip install --upgrade pip setuptools wheel pip3 install --upgrade pip setuptools
If the error is not resolved, try to uninstall setuptools
and then install the
module.
# ๐๏ธ Uninstall setuptools pip3 uninstall setuptools # ๐๏ธ Install setuptools pip3 install setuptools # ๐๏ธ If you don't have pip set up in PATH python3 -m pip install setuptools
Alternatively, you can use the
official get-pip script to
install setuptools
.
Download the script from https://bootstrap.pypa.io/get-pip.py by clicking on the link, right-clicking and selecting "Save as" in your browser.
get-pip.py
file is downloaded and run the following command.# ๐๏ธ On Linux or MacOS python get-pip.py # ๐๏ธ Using python 3 python3 get-pip.py # ๐๏ธ On Windows py get-pip.py
The get-pip.py
script installs or upgrades pip
and installs setuptools
and
wheel
if they aren't installed already.
The Python error "ModuleNotFoundError: No module named 'setuptools_rust'" occurs for multiple reasons:
setuptools-rust
package installed by running
pip install setuptools-rust
.pip
.setuptools_rust
which would shadow the official module.setuptools_rust
which would shadow the imported
variable.If the error persists, get your Python version and make sure you are installing the package using the correct Python version.
python --version
For example, my Python version is 3.10.4
, so I would install the
setuptools-rust
package with pip3.10 install setuptools-rust
.
pip3.10 install setuptools-rust # ๐๏ธ If you get a permissions error use pip3 (NOT pip3.X) sudo pip3 install setuptools-rust
Notice that the version number corresponds to the version of pip
I'm using.
If the PATH for pip
is not set up on your machine, replace pip
with
python3 -m pip
:
# ๐๏ธ Make sure to use your version of Python, e.g. 3.10 python3 -m pip install setuptools-rust
If the error persists, try restarting your IDE and development server/script.
You can
check if you have the setuptools-rust
package installed
by running the pip show setuptools-rust
command.
# ๐๏ธ Check if you have setuptools-rust installed pip show setuptools-rust # ๐๏ธ If you don't have pip set up in PATH python -m pip show setuptools-rust
The pip show setuptools-rust
command will either state that the package is not
installed or show a bunch of information about the package, including the
location where the package is installed.
If the package is not installed, make sure your IDE is using the correct version of Python.
setuptools-rust
package using the incorrect version or your IDE might be set up to use a different version.For example, In VSCode, you can press CTRL + Shift + P
or (โ
+ Shift
+ P
on Mac) to open the command palette.
Then type "Python select interpreter" in the field.
Then Select the correct Python version from the dropdown menu.
If you are using a virtual environment, make sure you are installing
setuptools-rust
in your virtual environment and not globally.
You can try creating a virtual environment if you don't already have one.
# ๐๏ธ Use the correct version of Python when creating VENV python3 -m venv venv # ๐๏ธ Activate on Unix or MacOS source venv/bin/activate # ๐๏ธ Activate on Windows (cmd.exe) venv\Scripts\activate.bat # ๐๏ธ Activate on Windows (PowerShell) venv\Scripts\Activate.ps1 # ๐๏ธ Install setuptools-rust in your virtual environment pip install setuptools-rust
If the python3 -m venv venv
command doesn't work, try the following 2
commands:
python -m venv venv
py -m venv venv
Your virtual environment will use the version of Python that was used to create it.
setuptools_rust.py
because that would shadow the original setuptools-rust
module.You also shouldn't be declaring a variable named setuptools_rust
as that would
also shadow the original module.
If the error is not resolved, try to uninstall the setuptools-rust
package and
then install it.
# ๐๏ธ Check if you have setuptools-rust installed pip show setuptools-rust # ๐๏ธ If you don't have pip set up in PATH python -m pip show setuptools-rust # ๐๏ธ Uninstall setuptools-rust pip uninstall setuptools-rust # ๐๏ธ If you don't have pip set up in PATH python -m pip uninstall setuptools-rust # ๐๏ธ Install setuptools-rust pip install setuptools-rust # ๐๏ธ If you don't have pip set up in PATH python -m pip install setuptools-rust
Try restarting your IDE and development server/script.
You can also try to upgrade the version of the setuptools-rust package.
pip install setuptools-rust --upgrade # ๐๏ธ If you don't have pip set up in PATH python -m pip install setuptools-rust --upgrade
This one is for using virtual environments (VENV) on Windows
:
This one is for using virtual environments (VENV) on MacOS
and Linux
: