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

相关推荐
Escalating_xu1 天前
【Python】使用库:标准库、第三方库、pip、项目实战与程序打包
java·python·pip
青春不朽5123 天前
pip 安装慢、超时、报错?一份国内源配置 + 9 个高频报错对照表
pip
ysu_03145 天前
uv实战指南-从Python版本虚拟环境到pyproject依赖管理
开发语言·python·pip·uv·虚拟环境·包管理·依赖管理
伞伞悦读16 天前
【第39期】Python 第三方包安装详解:pip、conda、requirements、版本锁定和镜像源
python·conda·pip
H Journey17 天前
pip 和uv 开发和部署python项目
python·pip·uv
北城笑笑20 天前
Python Dev 02 & Tkinter webbrowser 实战,手写第一个 Python 桌面 GUI 小工具
人工智能·python·pip
王_teacher22 天前
pycharm 无法将“pip”项识别为 cmdlet、函数、脚本文件或可运行程序的名称
pycharm·pip·pycharm配置·无法将“pip”项识别·无法将pip项识别
zhangzeyuaaa1 个月前
深入理解 pip install .:安装当前目录项目的正确姿势
人工智能·python·pip
头茬韭菜1 个月前
第 1 篇:「架构鸟瞰与 Memory 初始化」—— 从 pip install 到三个工厂
jvm·架构·pip·mem0