在 macOS 上安装 data.table

4

我需要在macOS 11.1上安装data.table 1.12.0(特定版本)。

我遇到了一个错误:

clang: error: unsupported option '-fopenmp'
make: *** [assign.o] Error 1

我按照https://github.com/Rdatatable/data.table/wiki/Installation#openmp-enabled-compiler-for-mac中的指示操作,但仍然无法使其工作。 R版本为3.6.1。
我还尝试使用R CMD install命令,但出现了相同的错误。
R CMD install data.table_1.12.0.tar.gz 
* installing to library ‘/Users/XXX/Library/R/3.6/library’
* installing *source* package ‘data.table’ ...
** package ‘data.table’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
clang -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
clang: error: unsupported option '-fopenmp'
make: *** [assign.o] Error 1
ERROR: compilation failed for package ‘data.table’
* removing ‘/Users/XXX/Library/R/3.6/library/data.table’

更新:似乎我也无法从CRAN安装最新的data.table,所以这个问题并不仅局限于1.12.0版本。

虽然没有任何答案被接受,但它们已经被其他人点赞,表明它们的价值。请参见https://dev59.com/GVcP5IYBdhLWcg3w9-ra - r2evans
2个回答

7

注意:此解决方案适用于英特尔处理器(不适用于苹果M1芯片)

以下是我使用的步骤,以启用多线程/ openMP从源代码安装data.table(最初在https://dev59.com/Z1EG5IYBdhLWcg3wfPPB#65334247中描述):

  1. 重新安装xcode命令行工具(即使显示“最新”)
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install
  1. 通过 Homebrew 安装 gcc 和 llvm(安装 Homebrew 操作指南),如果您已经通过 Homebrew 安装了 gcc/llvm,请跳过此步骤。
# This can take several hours
brew install gcc
brew install llvm
  1. 一旦你通过Homebrew安装了gcc和llvm:
brew cleanup
brew update
brew upgrade
brew reinstall gcc
brew reinstall llvm
  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
  1. 安装gmp库:
brew install gmp
  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++
  1. 在R/Rstudio中从源代码编译data.table
install.packages("data.table", type = "source")

# To check whether it installed correctly, run:
library(data.table)

如果你的程序包编译失败,一些Stack Overflow用户曾经不得不安装全新的gfortran (参考:https://dev59.com/Z1EG5IYBdhLWcg3wfPPB#65334247),你可以从https://github.com/fxcoudert/gfortran-for-macOS/releases下载它。

对于 Monterey,这是 gfortran 下载链接:https://github.com/fxcoudert/gfortran-for-macOS/releases - 24lindsey
2022年5月的指南中是否还有其他更新? - 24lindsey
1
已更新至2022年5月,以修复data.table依赖项(RcppAlgos)中的一个问题。 - jared_mamrot
1
这是我在尝试了数小时后终于成功的!谢谢。 - Gordon McDonald

0
这是我的方法:
基本上,您需要下载 clangllvmorg
curl -SL https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz \
   | tar -xJC . && \
   mv clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04 clang_10.0.0 && \
   echo 'export PATH=/clang_10.0.0/bin:$PATH' >> ~/.bashrc && \
   echo 'export LD_LIBRARY_PATH=/clang_10.0.0/lib:$LD_LIBRARY_PATH' >> ~/.bashrc

确保它们在你的PATHLD_LIBRARY_PATH中列出

然后获取datatable并从源代码构建

git clone https://github.com/h2oai/datatable.git && \
   cd datatable && \
   make build && \
   python -m pip install ../datatable/

确保你正在使用正确的Python版本


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接