gpt4 book ai didi

r - 使用 devtools::install_github() 安装无法检测到构建工具

转载 作者:行者123 更新时间:2023-12-03 17:09:38 24 4
gpt4 key购买 nike

这是我第一次尝试下载 Github 包,我在 MacOS Big Sur v11.2.1 上使用 RStudio v1.2.5033 时遇到了一些问题。
最初,当运行

library(devtools)
devtools::install_github('xuyiqing/gsynth')
我收到此错误:
Warning in install.packages :
installation of package ‘gsynth’ had non-zero exit status
看了一些资料,看来我需要下载命令行工具,所以我下载了 XCode CLI、clang4 和 gfortran。现在我收到一条弹出消息:
"安装构建工具
从源代码构建 R 包需要安装额外的构建工具。
是否要立即安装附加工具?
是/否”
如果我单击“否”,则会收到此错误:
Error: Failed to install 'gsynth' from GitHub:
Could not find tools necessary to compile a package
Call `pkgbuild::check_build_tools(debug = TRUE)` to diagnose the problem.
在 R 控制台中运行上面的 pkgbuild 代码,这就是我得到的:
Trying to compile a simple C file
Error: Could not find tools necessary to compile a package
Call `pkgbuild::check_build_tools(debug = TRUE)` to diagnose the problem.
rror: Could not find tools necessary to compile a package

最佳答案

看起来你需要解决一些问题来安装这个包(xcode 命令行工具和 OpenMP 支持),但如果你按照这里的说明操作,你应该解决这些问题:https://stackoverflow.com/a/65334247/12957340
进行必要的更改后,我使用 devtools::install_github('xuyiqing/gsynth') 在我的系统(macOS Big Sur 11.2.3/R 版本 4.0.3)上成功安装了 gsynth。没有问题。
——
以下是万一上面的链接失效的说明:

  • 重新安装 xcode 命令行工具(即使它说“最新”)
  • sudo rm -rf /Library/Developer/CommandLineTools
    sudo xcode-select --install
  • 通过 Homebrew ( instructions for installing Homebrew ) 安装 gcc 和 llvm 或者,如果您已经通过 Homebrew 安装了 gcc/llvm,请跳到下一步
  • # This can take several hours
    brew install gcc
    brew install llvm
  • 通过 Homebrew 安装 gcc 和 llvm 后:
  • brew cleanup
    brew update
    brew upgrade
    brew reinstall gcc
    brew reinstall llvm
  • 将一些头文件链接到/usr/local/include
  • sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/* /usr/local/include/

    # You can safely ignore warnings like this:
    #ln: /usr/local/include//tcl.h: File exists
    #ln: /usr/local/include//tclDecls.h: File exists
    #ln: /usr/local/include//tclPlatDecls.h: File exists
    #ln: /usr/local/include//tclTomMath.h: File exists
    #ln: /usr/local/include//tclTomMathDecls.h: File exists
    #ln: /usr/local/include//tk.h: File exists
    #ln: /usr/local/include//tkDecls.h: File exists
    #ln: /usr/local/include//tkPlatDecls.h: File exists
  • 新建 ~/.R/Makevars文件(如果您已经有 ~/.R/Makevars 文件,请将其保存在不同的目录中(远离 ~/.R/ )并在文件中仅包含以下行:
  • FLIBS=-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin19/10.2.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm
    CXX1X=/usr/local/gfortran/bin/g++
    CXX98=/usr/local/gfortran/bin/g++
    CXX11=/usr/local/gfortran/bin/g++
    CXX14=/usr/local/gfortran/bin/g++
    CXX17=/usr/local/gfortran/bin/g++

    LLVM_LOC = /usr/local/opt/llvm
    CC=/usr/local/gfortran/bin/gcc -fopenmp
    CXX=/usr/local/gfortran/bin/g++ -fopenmp
    CFLAGS=-g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe
    CXXFLAGS=-g -O3 -Wall -pedantic -std=c++11 -mtune=native -pipe
    LDFLAGS=-L/usr/local/opt/gettext/lib -L$(LLVM_LOC)/lib -Wl,-rpath,$(LLVM_LOC)/lib
    CPPFLAGS=-I/usr/local/opt/gettext/include -I$(LLVM_LOC)/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
  • 从 R/Rstudio 中的源代码编译包
  • # To check whether openmp is enabled, compile data.table:
    install.packages("data.table", type = "source")
  • 如果你的包编译失败,几个 SO 用户不得不安装一个新的 gfortran(re: https://stackoverflow.com/a/65334247/12957340),你可以从 https://github.com/fxcoudert/gfortran-for-macOS/releases/tag/10.2-bigsur-intel 下载。
  • 关于r - 使用 devtools::install_github() 安装无法检测到构建工具,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66359031/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com