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

相关推荐
三十..2 小时前
Redis 核心原理与高可用架构实践
运维·数据库·redis
会Tk矩阵群控的小木3 小时前
基于Python的iMessage短信群发与社媒多账号统一管理系统实现
开发语言·windows·python·新媒体运营·开源软件·个人开发
质造者3 小时前
LangChain + Ollama + Tavily 实现旅游问答系统
linux·人工智能·python·langchain·rag
伊布拉西莫4 小时前
【流畅的Python】第20章:并发执行器 — 学习笔记
笔记·python·学习
IT策士4 小时前
Redis 从入门到精通:Python 操作 Redis
redis·python·bootstrap
曾小蛙4 小时前
【TWIST2】 PICO重映射G1在ubuntu 22.04下环境配置
ubuntu·g1·twist2·gmr2·pico4u·xrobotoolkit
编码者卢布4 小时前
【Azure AI Search】 searchMode=any 和 searchMode=all 有什么区别?
人工智能·python·flask
Samooyou4 小时前
大模型微调(Fine Tuning)
人工智能·python·ai·语言模型
qq_8573058194 小时前
python语法
开发语言·python·算法
starvapour4 小时前
Ubuntu部署gitlab频繁出现502的问题
linux·ubuntu·gitlab