Skip to content

How to fix error: can’t find Rust compiler?

  • by
  • 3 min read
Top 7 games for kids to learn coding | Candid.Technology

Python is one of the most popular programming languages at the time, mostly because of its ease of use and the availability of hundreds of thousands of libraries and APIs that further extend the functionality of the language. 

However, as simple as writing code has become, it still throws challenges at developers, often uncalled-for bugs and glitches. In this article, we’re talking about the “error: can’t find Rust compiler” error in Python, its causes and what you can do to fix the problem.


What causes this error?

The error mostly happens when installing the cryptography library, which requires Rust during installation. Specifically, versions higher than 3.5 require Rust to be installed. Any version before this allows users to skip the Rust requirement and build the library regardless.

Also read: How to fix Preauth.account_not_found_error.body?


How to fix this?

Here are three fixes you can try out. 

Install Rust

The simplest fix to the problem is to install Rust. You can skip the installation, as detailed in the solution given below, but that can set you up for future issues as you’ll have to use version 3.4 or lower. 

You don’t have to do anything special to install Rust, modify your RUN apk add command to the one given below and you should be good to go. 

FROM python:3.7-alpine

ENV PYTHONUNBUFFERED 1

RUN apk add --update \
  build-base \
  cairo \
  cairo-dev \
  cargo \
  freetype-dev \
  gcc \
  gdk-pixbuf-dev \
  gettext \
  jpeg-dev \
  lcms2-dev \
  libffi-dev \
  musl-dev \
  openjpeg-dev \
  openssl-dev \
  pango-dev \
  poppler-utils \
  postgresql-client \
  postgresql-dev \
  py-cffi \
  python3-dev \
  rust \
  tcl-dev \
  tiff-dev \
  tk-dev \
  zlib-dev

RUN pip install cryptography

Do keep in mind that we’re assuming you’re using version 3.7-alpine. If you’re using another Python version, modify the command accordingly. 

Also read: How to fix error: getaddrinfo enotfound?


Skip the Rust installation

If you’re using cryptography version 3.4 or lower, you can skip the Rust requirement by adding the following line before adding commands for the build. 

ENV CRYPTOGRAPHY_DONT_BUILD_RUST=1
What is Metadata? Types and benefits | Candid.Technology
Photo by Shahadat Shemul

Alternatively, you can add this line to your pyvenv.cfg file if you’re running virtual environments. After that, you can install cryptography using Pip as follows.

pip install cryptography

Update Pip

Some users have reported that simply updating Pip resolved their issue. Try running the following command to update Pip. 

pip install -U pip

Upgrading to Pip version 19.1,1 or higher can fix the problem as newer versions automatically install any precompiled packages, hence reducing the number of manual dependency installs users have to make. 

Check out our detailed guide on how to upgrade the Pip version for more details. 

Also read: How to fix Fatal error: Python.h: No such file or directory?

nv-author-image

Yadullah Abidi

Yadullah is a Computer Science graduate who writes/edits/shoots/codes all things cybersecurity, gaming, and tech hardware. When he's not, he streams himself racing virtual cars. He's been writing and reporting on tech and cybersecurity with websites like Candid.Technology and MakeUseOf since 2018. You can contact him here: yadullahabidi@pm.me.

>