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

相关推荐
曲幽14 小时前
Python环境管理利器Conda:从入门到避坑实战指南
python·conda·pip·anaconda·uv·venv·miniconda
艾莉丝努力练剑14 小时前
【Python库和代码案例:第一课】Python 标准库与第三方库实战指南:从日期处理到 Excel 操作
java·服务器·开发语言·人工智能·python·pycharm·pip
9527(●—●)1 天前
windows系统python开发pip命令使用(菜鸟学习)
开发语言·windows·python·学习·pip
曲幽1 天前
Python包管理告别龟速下载:uv工具国内镜像与离线安装实战
python·conda·pip·uv·venv·uvx
曲幽2 天前
Python新利器:用uv轻松管理venv虚拟环境和pip依赖包
python·pip·uv·init·venv
阿关@3 天前
Vscode中Python无法将pip/pytest”项识别为 cmdlet、函数、脚本文件或可运行程序的名称
vscode·python·pip
Tipriest_4 天前
详细解释pip及其使用方法(对比apt)
大数据·elasticsearch·apt·pip
腾飞开源4 天前
40_Spring AI 干货笔记之 Transformers (ONNX) 嵌入
人工智能·huggingface·onnx·transformers·嵌入模型·spring ai·句子转换器
fengbingchun4 天前
GitHub上Transformers项目中模型组织结构
transformers
勇往直前plus5 天前
PyCharm 找不到包?Anaconda base 环境 pip 装到用户目录的排查与修复
ide·python·pycharm·conda·pip