pip install transformers教程

直接pip install transformers会报错,报错内容如下:

shell 复制代码
Collecting safetensors>=0.3.1 (from transformers)
  Using cached safetensors-0.5.2.tar.gz (66 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [6 lines of output]
      
      Cargo, the Rust package manager, is not installed or is not on PATH.
      This package requires Rust and Cargo to compile extensions. Install it through
      the system's package manager or via https://rustup.rs/
      
      Checking for Rust toolchain....
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

重点是Cargo, the Rust package manager, is not installed or is not on PATH这句话,所以可能Rust没有安装,那我们安装Rust,参考网址,具体步骤:

shell 复制代码
# 确认一下你的curl是不是用snap安装的
sudo snap list | grep curl
# 如果是,卸载
sudo snap remove curl
# 然后用apt重新安装
sudo apt install curl
# 安装Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# 添加环境变量
source $HOME/.cargo/env
# 测试是否安装成功
rustc -V 

Rust安装成功后再pip install transformers即可

相关推荐
F_D_Z12 小时前
【删库跑路】一次删除pip的所有第三方库
pip
wa的一声哭了2 天前
python基础知识pip配置pip.conf文件
java·服务器·开发语言·python·pip·risc-v·os
白毛大侠3 天前
在 Ubuntu 24.04 中安装 Python 2.7、pip 及 mysqlclient==1.4.6 的完整指南
python·ubuntu·pip
-dzk-4 天前
【Flask】基础入门
后端·python·pycharm·django·flask·conda·pip
X.Cristiano6 天前
pip 安装加速指南:配置国内镜像源(中国科技大学、清华、阿里云等)
pip
小石潭记丶10 天前
Django服务开发镜像构建
django·sqlite·pip
Tipriest_22 天前
sudo安装pip包的影响
python·pip·sudo
ajassi200024 天前
开源 python 应用 开发(一)python、pip、pyAutogui、python opencv安装
python·opencv·开源·pip
猫头虎24 天前
2025最新Python 100个常用函数在线体验项目
android·java·python·pycharm·django·pandas·pip
CaracalTiger1 个月前
HTTP 协议的基本概念(请求/响应流程、状态码、Header、方法)问题解决方案大全
开发语言·网络·python·深度学习·网络协议·http·pip