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博客

相关推荐
山海青风11 分钟前
OpenAI 实战进阶教程 - 第七节: 与数据库集成 - 生成 SQL 查询与优化
数据库·人工智能·python·sql
yaoxtao1 小时前
Docker的镜像
运维·docker·容器
不一样的信息安全1 小时前
Docker环境下Nacos的保姆级安装教程
运维·docker·容器
小Tomkk1 小时前
Docker 部署 Starrocks 教程
运维·starrocks·docker·容器
玥轩_5212 小时前
《Linux服务与安全管理》| 数据库服务器安装和配置
linux·运维·服务器·数据库·安全·网络安全·redhat
金融OG2 小时前
98.2 AI量化开发:基于DeepSeek打造个人专属金融消息面-AI量化分析师(理论+全套Python代码)
人工智能·python·算法·机器学习·数学建模·金融
江湖有缘3 小时前
Linux系统之whereis命令的基本使用
linux·运维·服务器
老大白菜3 小时前
在 Ubuntu 中使用 Conda 创建和管理虚拟环境
linux·ubuntu·conda
山海青风3 小时前
OpenAI 实战进阶教程 - 第四节: 结合 Web 服务:构建 Flask API 网关
前端·人工智能·python·chatgpt·flask
白嫖勇者3 小时前
Python(Pandas)数据分析学习
python·数据分析·pandas