在 macOS 上安装 data.table

Fly*_*kle 4 macos r data.table

我需要在 macOS 11.1 上安装 data.table 1.12.0(特别是)。

\n

我收到错误:

\n
clang: error: unsupported option \'-fopenmp\'\nmake: *** [assign.o] Error 1\n
Run Code Online (Sandbox Code Playgroud)\n

我已按照https://github.com/Rdatatable/data.table/wiki/Installation#openmp-enabled-compiler-for-mac中的说明进行操作,但仍然无法使其正常工作。\nR 3.6.1。

\n

我还尝试了 R CMD 安装并得到了相同的错误:

\n
R CMD install data.table_1.12.0.tar.gz \n* installing to library \xe2\x80\x98/Users/XXX/Library/R/3.6/library\xe2\x80\x99\n* installing *source* package \xe2\x80\x98data.table\xe2\x80\x99 ...\n** package \xe2\x80\x98data.table\xe2\x80\x99 successfully unpacked and MD5 sums checked\n** using staged installation\n** libs\nclang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fopenmp -fPIC  -Wall -g -O2  -c assign.c -o assign.o\nclang: error: unsupported option \'-fopenmp\'\nmake: *** [assign.o] Error 1\nERROR: compilation failed for package \xe2\x80\x98data.table\xe2\x80\x99\n* removing \xe2\x80\x98/Users/XXX/Library/R/3.6/library/data.table\xe2\x80\x99\n
Run Code Online (Sandbox Code Playgroud)\n

更新:对我来说从 CRAN 安装最新的 data.table 似乎也是一个问题,所以它显然不限于 1.12.0。

\n

jar*_*rot 8

注意。该解决方案适用于 Intel 处理器(不适用于 Apple M1 芯片)

这些是我在启用多线程/openMP 的情况下从源安装 data.table 的步骤(最初在/sf/answers/4573397321/中描述):

  1. 重新安装 xcode 命令行工具(即使它说“最新”)
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install
Run Code Online (Sandbox Code Playgroud)
  1. 通过 Homebrew 安装 gcc 和 llvm (安装 Homebrew 的说明),或者,如果您已经通过 Homebrew 安装了 gcc/llvm,请跳到下一步
# This can take several hours
brew install gcc
brew install llvm
Run Code Online (Sandbox Code Playgroud)
  1. 通过 Homebrew 安装 gcc 和 llvm 后:
brew cleanup
brew update
brew upgrade
brew reinstall gcc
brew reinstall llvm
Run Code Online (Sandbox Code Playgroud)
  1. 将一些标头链接到 /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
Run Code Online (Sandbox Code Playgroud)
  1. 安装gmp 库
brew install gmp
Run Code Online (Sandbox Code Playgroud)
  1. 创建一个新~/.R/Makevars文件(如果您已有~/.R/Makevars文件,请将其保存在不同的目录中(远离~/.R/))并在文件中仅包含以下行:
LOC=/usr/local/gfortran
CC=$(LOC)/bin/gcc -fopenmp
CXX=$(LOC)/bin/g++ -fopenmp
CXX11 = $(LOC)/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$(LOC)/lib -Wl,-rpath,$(LOC)/lib,-L/usr/local/lib
CPPFLAGS=-I$(LOC)/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/usr/local/include

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++
Run Code Online (Sandbox Code Playgroud)
  1. 从 R/Rstudio 中的源代码编译 data.table
install.packages("data.table", type = "source")

# To check whether it installed correctly, run:
library(data.table)
Run Code Online (Sandbox Code Playgroud)
  1. 如果你的包无法编译,一些 SO 用户必须安装一个新的 gfortran (re: /sf/answers/4573397321/ ),你可以从https://github.com/下载fxcoudert/gfortran-for-macOS/releases