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即可

相关推荐
烂蜻蜓2 天前
NumPy 教程(二):安装与验证——pip、conda 与发行版选型
conda·numpy·pip
prince_zxill18 天前
PEP 751 pylock.toml 实测:pip 26.3 装 6 个包版本全钉死,但 [web] 选不中任何东西
python·pip·依赖管理·pep 751
2601_9679791222 天前
pip在Python中的9个必须知道的用法
python·pip·版本控制·包管理工具·requirements.txt
2601_9679791222 天前
纯手写:Python安装pip完整教程,搞了几小时,终于成功
python·教程·pip·安装·包管理
沧海一笑-dj1 个月前
【Python】Python学习笔记-模块与包
python·pip·模块·包·python包·python模块·包与模块
郝学胜-神的一滴1 个月前
AI 编程智能体 16:从零基础搭建到精细化优化
人工智能·python·算法·语言模型·langchain·pip
All The Way North-1 个月前
Transformers 5.19.0 源码阅读:AutoTokenizer.decode() 原生批处理与 BPE 空格清理陷阱
transformers·tokenizer·版本更新·decode·源码解读·autotokenizer·v 5.19
All The Way North-1 个月前
Transformers 5.19.0 首发源码研读:Tokenizer.call() 核心机制与实战验证
huggingface·transformers·qwen·tokenizer·源码解读·autotokenizer·v 5.19
万粉变现经纪人1 个月前
如何解决 pip install 安装报错 检测到 yanked 版本需更换可用版本 问题
人工智能·python·scrapy·numpy·pandas·pyqt·pip
jiangliushi61 个月前
GPT-6.1 Sol 免费用:pip install 太慢、超时?换清华镜像,再让 Codex 帮你写脚本
gpt·pip