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

相关推荐
hui函数3 小时前
如何解决 pip install 编译报错 g++: command not found(缺少 C++ 编译器)问题
开发语言·c++·pip
hui函数6 小时前
Python系列Bug修复|如何解决 pip install -e . 安装报错 “后端不支持可编辑安装(PEP 660)” 问题
python·bug·pip
hui函数7 小时前
如何解决 pip install 网络报错 403 Forbidden(访问被阻止)问题
网络·pip
一尘之中8 小时前
在Ubuntu 22.04中高效使用pip:从入门到精通
ubuntu·pip·ai写作
hui函数8 小时前
如何解决 PyCharm 控制台 pip install 报错 OSError: [Errno 122] Disk quota exceeded 问题
ide·pycharm·pip
寻星探路10 小时前
【Python 全栈测开之路】Python 进阶:库的使用与第三方生态(标准库+Pip+实战)
java·开发语言·c++·python·ai·c#·pip
hui函数19 小时前
如何解决 PyCharm 控制台 pip install 报错 UnicodeDecodeError/GBK 路径编码问题
ide·pycharm·pip
hui函数1 天前
如何解决 pip install 网络报错 ERROR: No matching distribution found for requests
网络·pip
hui函数1 天前
如何解决 PyCharm 控制台 pip install 报错 BadZipFile: File is not a zip file问题
ide·pycharm·pip
hui函数1 天前
如何解决 pip install 安装报错 Invalid wheel filename ‘xxx.wh1’(文件名不合法)问题
pip