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

相关推荐
HAPPY酷3 天前
Flutter 开发环境搭建全流程
android·python·flutter·adb·pip
万粉变现经纪人4 天前
如何解决 pip install 编译报错 ‘cl.exe’ not found(缺少 VS C++ 工具集)问题
开发语言·c++·人工智能·python·pycharm·bug·pip
爱吃面条的猿6 天前
Python修改pip install 指定安装包的路径和默认镜像源
linux·python·pip
中科院提名者6 天前
Conda与Pip混用导致的“幽灵包”现象
conda·pip
九河_10 天前
解决pip install gym==0.19.0安装失败问题
开发语言·python·pip·gym
小oo呆11 天前
【学习心得】conda打包进行环境迁移遇到conda包和pip包管理冲突问题
conda·pip
Stara051112 天前
DeepSeek-OCR私有化部署—从零构建OCR服务环境
计算机视觉·docker·ocr·transformers·vllm·deepseek·光学符号识别
万粉变现经纪人20 天前
如何解决 pip install 安装报错 [WinError 32] 文件被占用(杀毒/占用进程)问题
python·pycharm·flask·beautifulsoup·bug·pandas·pip
PKNLP20 天前
11.大模型Agent应用
python·agent·pip
fengbingchun20 天前
GitHub上Transformers项目中推理函数pipeline的使用
transformers