ModuleNotFoundError: No module named 'setuptools' in Python

avatar
Borislav Hadzhiev

Last updated: Apr 8, 2024
7 min

banner

# Table of Contents

  1. ModuleNotFoundError: No module named 'setuptools' in Python
  2. ModuleNotFoundError: No module named 'setuptools_rust'

# ModuleNotFoundError: No module named 'setuptools' in Python

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.

shell
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.

shell
# ๐Ÿ‘‡๏ธ Uninstall setuptools pip uninstall setuptools pip3 uninstall setuptools # ๐Ÿ‘‡๏ธ Install setuptools pip install setuptools pip3 install setuptools

# Upgrade your version of setuptools

You can also try to upgrade the version of the setuptools package.

shell
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

# Using the official installer to 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.

Open your terminal in the location where the get-pip.py file is downloaded and run the following command.

shell
# ๐Ÿ‘‡๏ธ 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.

# Using a virtual environment instead

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.

shell
# ๐Ÿ‘‡๏ธ 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.

# ModuleNotFoundError: No module named 'setuptools_rust'

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.

modulenotfounderror no module named setuptools rust

First, make sure your 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.

shell
# ๐Ÿ‘‡๏ธ 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.

shell
# ๐Ÿ‘‡๏ธ 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.

shell
# ๐Ÿ‘‡๏ธ 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.

shell
# ๐Ÿ‘‡๏ธ 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.

Open your terminal in the location where the get-pip.py file is downloaded and run the following command.
shell
# ๐Ÿ‘‡๏ธ 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.

# Common causes of the error

The Python error "ModuleNotFoundError: No module named 'setuptools_rust'" occurs for multiple reasons:

  1. Not having the setuptools-rust package installed by running pip install setuptools-rust.
  2. Having an outdated version of pip.
  3. Installing the package in a different Python version than the one you're using.
  4. Installing the package globally and not in your virtual environment.
  5. Your IDE running an incorrect version of Python.
  6. Naming your module setuptools_rust which would shadow the official module.
  7. Declaring a variable named 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.

shell
python --version

get 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.

shell
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:

shell
# ๐Ÿ‘‡๏ธ 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.

# Check if the package is installed

You can check if you have the setuptools-rust package installed by running the pip show setuptools-rust command.

shell
# ๐Ÿ‘‡๏ธ 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.

# Make sure your IDE is using the correct Python version

If the package is not installed, make sure your IDE is using the correct version of Python.

If you have multiple Python versions installed on your machine, you might have installed the 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.

python select interpreter

Then Select the correct Python version from the dropdown menu.

select correct python version

Your IDE should be using the same version of Python (including the virtual environment) that you are using to install packages from your terminal.

If you are using a virtual environment, make sure you are installing setuptools-rust in your virtual environment and not globally.

# Install the package in a Virtual Environment

You can try creating a virtual environment if you don't already have one.

shell
# ๐Ÿ‘‡๏ธ 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.

If the error persists, make sure you haven't named a module in your project as 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.

# Try reinstalling the package

If the error is not resolved, try to uninstall the setuptools-rust package and then install it.

shell
# ๐Ÿ‘‡๏ธ 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.

shell
pip install setuptools-rust --upgrade # ๐Ÿ‘‡๏ธ If you don't have pip set up in PATH python -m pip install setuptools-rust --upgrade
If the error persists, I would suggest watching a quick video on how to use Virtual environments in Python.

This one is for using virtual environments (VENV) on Windows:

This one is for using virtual environments (VENV) on MacOS and Linux:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev