Ubuntu 安装transformers 报错error can‘t find rust compiler

问题描述

Ubuntu 20.04 使用 pip 安装 transformers 库遇到报错:error: can't find Rust compiler. 下面是报错信息的后半部分。

复制代码
running build_ext
      running build_rust
      error: can't find Rust compiler

      If you are using an outdated pip version, it is possible a prebuilt wheel is available for this package but pip is not able to install from it. Installing from the wheel would avoid the need for a Rust compiler.

      To update pip, run:

          pip install --upgrade pip

      and then retry package installation.

      If you did intend to build this package from source, try installing a Rust compiler from your system package manager and ensure it is on the PATH during installation. Alternatively, rustup (available at https://rustup.rs) is the recommended way to download and update the Rust compiler toolchain.
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for tokenizers
Failed to build tokenizers
ERROR: Could not build wheels for tokenizers, which is required to install pyproject.toml-based projects

解决方案

bash 复制代码
sudo apt install rustc
sudo apt install cargo

完成上面两个库的安装重新执行 transformers 的安装即可,库较大可能需要 build 一段时间。(我这边用时2分钟左右)

bash 复制代码
pip install transformers

详细流程

按照提示更新了 pip:

复制代码
pip install --upgrade pip

但是没有任何作用。报错信息不变。那只能考虑安装 Rust。

参考资料:How to Install Rust on Ubuntu {apt and rustup}

这个用 apt 安装的看上去是最简单的:

bash 复制代码
sudo apt install rustc

安装完毕后依旧报错:

bash 复制代码
      error: [Errno 2] No such file or directory: 'cargo'
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for tokenizers
Failed to build tokenizers
ERROR: Could not build wheels for tokenizers, which is required to install pyproject.toml-based projects

然后测试 apt 安装。

bash 复制代码
sudo apt install cargo

然后重新 pip 安装,问题解决。

相关工作

Windows 下同样问题的解决可参考:安装transformers报错error can't find rust compiler_can't find rust compiler-CSDN博客

相关推荐
咖啡の猫5 小时前
Python字典推导式
开发语言·python
曹文杰15190301125 小时前
2025 年大模型背景下应用统计本科 计算机方向 培养方案
python·线性代数·机器学习·学习方法
Wulida0099916 小时前
建筑物表面缺陷检测与识别:基于YOLO11-C3k2-Strip模型的智能检测系统
python
FJW0208146 小时前
Python_work4
开发语言·python
爱笑的眼睛117 小时前
从 Seq2Seq 到 Transformer++:深度解构与自构建现代机器翻译核心组件
java·人工智能·python·ai
tuokuac7 小时前
docker中nginx配置报错解决
linux·运维·服务器
yaoh.wang7 小时前
力扣(LeetCode) 88: 合并两个有序数组 - 解法思路
python·程序人生·算法·leetcode·面试·职场和发展·双指针
执笔论英雄7 小时前
【RL】slime创建actor的流程
python
吴佳浩 Alben7 小时前
Python入门指南(四)
开发语言·后端·python
小智RE0-走在路上8 小时前
Python学习笔记(8) --函数的多返回值,不同传参,匿名函数
笔记·python·学习