ModuleNotFoundError: No module named ‘setuptools_rust’

Are you looking for the solution to the error “ModuleNotFoundError: No module named ‘setuptools_rust’“? Yes, you have come to the right place. Today I will show you how to solve this error.

The error “modulenotfounderror: no module named setuptools_rust” occurs when we have an outdated version of PIP or forget to install the “setuptools_rust” module, or install it in the wrong environment.

[Fixed]: Error: metadata-generation-failed python

[Solution] modulenotfounderror: no module named setuptools_rust

To solve this error, you need to install the setuptools_rust Python package using the pip install setuptools-rust command.

Here is the command to install setuptools-rust in your system:

# If you are in a virtual environment or using Python 2
pip install setuptools-rust

# For python 3, could also be pip3.10
pip3 install setuptools-rust

# If you get permissions error you can run command as admin
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 if you don't have pip in your PATH environment variable
python3 -m pip install setuptools-rust

# Using py alias (Only works for Windows)
py -m pip install setuptools-rust

# If you are coding with Anaconda
conda install -c anaconda setuptools_rust

# If you are using Jupyter Notebook
!pip install setuptools-rust

When you successfully install setuptools-rust, you can import it like this:

from setuptools import setup
from setuptools_rust import Binding, RustExtension

setup(
    name="hello-rust",
    version="1.0",
    rust_extensions=[RustExtension("hello_rust.hello_rust",binding=Binding.PyO3)],
    packages=["hello_rust"],
    # rust extensions are not zip safe, just like C-extensions.
    zip_safe=False,
)

If your problem is still not resolved, you need to upgrade your PIP version. You can upgrade pip using the below commands according to your OS requirements.

# 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
pip install --upgrade pip --user

# upgrade pip for the current user
python -m pip install --user --upgrade pip
python3 -m pip install --user --upgrade pip

# Installing pip directly from get-pip.py (MacOS and Linux)
curl https://bootstrap.pypa.io/get-pip.py | python

# if you get permissions issues you can use this command
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

When you upgrade the PIP, you also need to upgrade ‘setuptools‘ and ‘wheels‘. You can update these packages by using these commands.

pip install --upgrade setuptools wheel

pip3 install --upgrade setuptools wheel

python3 -m pip install --upgrade setuptools wheel

The Python error “modulenotfounderror no module named ‘setuptools_rust’” can occur for multiple reasons:

  1. Not having setuptools_rust package installed. If you have not installed the setuptools_rust package then you can install it with this command “pip install setuptools-rust”.
  2. Installing the setuptools_rust package in a different python version than you are using.
  3. Installing the package in the global environment when you are using the virtual environment.
  4. You are using the incorrect version of python on your IDE. (e.g. VS Code)
  5. Using the file name “setuptools_rust.py”. If you are using a name like this setuptools_rust.py then consider it change to something else.
  6. Declaring a variable with the name “setuptools_rust”. If you have a variable setuptools_rust change its name to something else.

Conclusion on “modulenotfounderror: no module named setuptools_rust

Programmers, we discussed the Python error “modulenotfounderror no module named ‘setuptools_rust’“. I hope you have solved your Python error. If you have any questions about the tutorial or are still facing the error, please let us know in the comments section.

Leave a Reply