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

相关推荐
All The Way North-1 天前
【Transformers 实战——特征提取】从 Tokenizer 编码到 BERT 四类返回值详解与 NER 选型避坑
bert·huggingface·transformers·tokenizer·特征提取·pooler_output·last_hidden
猫头虎1 天前
城市级IP代理:赋能全球企业本地化数字增长与安全合规 | Decodo 德口多
网络·python·网络协议·tcp/ip·安全·pandas·pip
派葛穆5 天前
Python-pip切换镜像源
开发语言·python·pip
master33623 天前
python 安装pip
开发语言·python·pip
2601_9618752424 天前
花生十三资料1200题|题库|刷题
conda·pytest·pillow·pip·web3.py·ipython·gunicorn
FBI HackerHarry浩1 个月前
解决pip 安装 numpy 时元数据生成失败
numpy·pip
砍材农夫1 个月前
python环境|pip|uv|venv|Conda区别
后端·python·conda·pip·uv
砍材农夫1 个月前
python 如何一次性安装项目所有依赖包(pip和uv)
开发语言·python·pip·uv
小白弄潮儿1 个月前
Conda 使用入门指南(续):解决 pip 安装问题与最佳实践
conda·pip
Orchestrator_me1 个月前
Python pip install报SSL错误
python·ssl·pip