This post will show you how to fix the “ModuleNotFoundError: No module named setuptools_rust” error when installing packages in Python 3. We will also look at a cryptography module error that sometimes also occurs.
When does the error occur?
This error occurs when you install a Python 3 pip module, and the setuptools_rust module is not installed.
For example, the Python 3 modules mentioned below must the setuptools-rust plugin –
Install the Python Docker module:
pip3 install docker-compose
Install the Docker Compose module:
pip3 install docker-compose
Let us discuss the components
What is Python?
Python is a high-level, object-oriented programming language. It has a simple, easy-to-learn syntax that emphasizes readability and thus reduces the cost of program maintenance. Additionally, Python supports modules and packages, which encourages program modularity and code reuse via a pip package manager.
What is setuptools-rust?
According to Python Package Index (PyPI), setuptools-rust is a plugin for setuptools to build Rust Python extensions. As such, many packages use setuptools-rust. For example, the cryptography-obf package depends on setuptools-rust, as well as: hermes-python, prefetch2es, pyrogis, vtext, microvmi, rscase, pamagent, bc4py-extension, django-doclib, and many more.
Related setuptools_rust Python errors
You can experience a related error that setuptools_rust indirectly. For example, you can get an “error code 1 in /tmp/pip-build-y7ibkmns/cryptography/” error. If so, then this may be related to the “no module named setuptools_rust” error. This error makes sense since the cryptography module depends on setuptools-rust.
See below to see how they relate:
Collecting cryptography>=2.5 (from paramiko>=2.4.2; extra == "ssh"->docker[ssh]>=5->docker-compose) Using cached https://files.pythonhosted.org/packages/9b/77/461087a514d2e8ece1c975d8216bc03f7048e6090c5166bc34115afdaa53/cryptography-3.4.7.tar.gz Complete output from command python setup.py egg_info: Traceback (most recent call last): File "<string>", line 1, in <module> File "/tmp/pip-build-y7ibkmns/cryptography/setup.py", line 14, in <module> from setuptools_rust import RustExtension ModuleNotFoundError: No module named 'setuptools_rust' =============================DEBUG ASSISTANCE========================== If you are seeing an error here please try the following to successfully install cryptography: Upgrade to the latest pip and try again. This will fix errors for most users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip =============================DEBUG ASSISTANCE========================== ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-y7ibkmns/cryptography/
Let’s fix the setuptools_rust Python error!
You can fix the “setuptools_rust” error in Python by installing “setuptools_rust”:
pip3 install --upgrade --force-reinstall --no-cache-dir setuptools_rust
Additionally, you may want to do the same for the cryptography module:
pip3 install --upgrade --force-reinstall --no-cache-dir cryptography