在Mac M1/M2芯片上安装R包r-text时出现tokenizers构建失败错误
Mac M1/M2芯片R环境安装r-text包:解决tokenizers构建失败问题
执行textrpp_install()时出现以下报错:
Failed to build tokenizers
ERROR: Could not build wheels for tokenizers, which is required to install pyproject.toml-based projects
按以下步骤解决:
安装Xcode命令行工具(编译依赖)
在终端执行:xcode-select --install若已安装,会提示无需操作。
安装Rust环境(tokenizers编译依赖)
用Homebrew安装Rust:brew install rust配置环境变量(根据你的shell类型选择):
- zsh用户:
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.zshrc source ~/.zshrc - bash用户:
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.bash_profile source ~/.bash_profile
- zsh用户:
确保Python为ARM64架构版本
M1/M2需使用适配arm64的Python(如Homebrew安装的版本),避免用系统自带的x86版本。终端执行arch验证架构为arm64,python3 --version确认Python版本,若为x86版本,重新用Homebrew安装Python:brew install python在R中重新安装
先手动安装Python版tokenizers:reticulate::py_install("tokenizers", pip = TRUE)再执行:
textrpp_install()
内容的提问来源于stack exchange,提问作者Oscar Kjell
相关产品推荐
相关产品推荐

