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

相关推荐
卖个几把萌4 小时前
解决 Python 项目依赖冲突:使用 pip-tools 一键生成现代化的 requirements.txt
开发语言·python·pip
南_山无梅落1 天前
《uv 终极教程:安装、镜像配置与 pip 无缝迁移》
pip·uv
百锦再3 天前
python之路并不一马平川:带你踩坑Pandas
开发语言·python·pandas·pip·requests·tools·mircro
SunnyRivers3 天前
uv 与 pip:Python 包与依赖管理工具对比
python·pip·uv
cuckooman4 天前
uv设置国内源
python·pip·uv·镜像源
2501_903616994 天前
口碑好的养生时间app哪家专业
pip
旅途中的宽~5 天前
【Python】pip install -v e .命令不想自动更新torch版本
开发语言·python·pip
好大哥呀5 天前
如何使用pip创建和管理虚拟环境?
pip
阿正的梦工坊5 天前
pip install transformer_engine[pytorch]编译错误解决方法
pytorch·transformer·pip
于初见月5 天前
Conda环境中的pip究竟指向哪里?
python·conda·pip