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

相关推荐
DIY机器人工房几秒前
NAT 模式、命令行版、桥接模式方式给ubuntu虚拟机配网步骤:
linux·网络协议·ubuntu·嵌入式·桥接模式·diy机器人工房
wdfk_prog1 小时前
[Linux]学习笔记系列 -- lib/sort.c 通用的排序库(Generic Sorting Library) 为内核提供标准的、高效的排序功能
linux·运维·c语言·笔记·stm32·学习·bug
jump_jump1 小时前
前端部署工具 PinMe
运维·前端·开源
闲人编程1 小时前
深入理解Python的`if __name__ == ‘__main__‘`:它到底做了什么?
服务器·数据库·python·main·name·魔法语句
什么半岛铁盒1 小时前
C++项目:仿muduo库高并发服务器---------LoopThreadPool模块和TcpServer模块的实现
linux·服务器·c++·mysql·ubuntu
それども2 小时前
本地怎么远程调试服务器
运维·服务器
毕设源码-郭学长2 小时前
【开题答辩全过程】以 Python基于大数据的四川旅游景点数据分析与可视化为例,包含答辩的问题和答案
大数据·python·数据分析
Lin_Aries_04213 小时前
容器化 Flask 应用程序
linux·后端·python·docker·容器·flask
MediaTea3 小时前
Jupyter Notebook:基于 Web 的交互式编程环境
前端·ide·人工智能·python·jupyter