[Fixed] cargo rustc failed with code 101 – Could not build wheels for tokenizers, which is required to install pyproject.toml-based projects – Python

by
Ali Hasan
azure-pipelines boot2docker python python-wheel

Quick Fix: Set RUSTUP_TOOLCHAIN to the desired Rust version before building tokenizers to ensure the correct toolchain is used.

The Problem:

The user has a Dockerfile that includes a poetry install command, which tries to install the tokenizers library. However, the installation fails with the error "Could not build wheels for tokenizers, which is required to install pyproject.toml-based projects", and the exit code 101 is given. The user has been building the Dockerfile successfully in the past with the same dependencies, but it has recently started failing.

The Solutions:

Solution 1: Set RUSTUP_TOOLCHAIN Environment Variable

Adjust your Dockerfile to set the RUSTUP_TOOLCHAIN environment variable to the specific Rust toolchain version you want to use before building tokenizers. This ensures that the correct Rust toolchain is used during the build process. Here’s an updated Dockerfile:

RUN curl --proto ''=https'' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.66.1
ENV PATH="/root/.cargo/bin:${PATH}"
ENV RUSTUP_TOOLCHAIN=1.66.1

RUN poetry install --with main,dev

By setting RUSTUP_TOOLCHAIN to 1.66.1, you instruct the system to use Rust toolchain version 1.66.1 when building tokenizers. This should resolve the issue you’re facing.

Solution 2: Downgrade the Rust compiler to a version before 1.73.0

This error is likely caused by a change in the Rust compiler that is more sensitive to an issue in the tokenizers Rust code. Downgrading to an older version of the Rust compiler may resolve the issue.

  • Recommendation:

    1. Determine the operating system of the container.
    2. Find the package manager used to install software in the container.
    3. Check if the package manager provides a way to install a specific version of the Rust compiler.
    4. If possible, install an older version of the Rust compiler (e.g., Rust-1.72.1).
    5. Rebuild the Docker image.

This approach may resolve the issue and allow the tokenizers library to be installed successfully.

Q&A

How to fix cargo rustc failed due to could not build wheels for tokenizers?

Set the environment variable RUSTUP_TOOLCHAIN to the version of rust compiler you want to use.

Unable to install tokenizers, what is the fix?

Downgrade to Rust compiler version 1.72.1.

Video Explanation:

The following video, titled "Pip install sklearn error : Preparing metadata (pyproject.toml) error ...", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

i am getting the same error whhile installing pyqt5-tools in python 3.10 and i dont want to go to python 3.8 can you please tell me any ...