源码里没有configure_R4.0的源码安装——以mac为例

装了一堆东西回来,已经忘了最初要做的是啥。

太长不看版

其实就是缺什么安装什么。每个人情况可能都不太一样。对于我的mac上,如下:

  • configure之前需要安装:
    • gcc
    • xz
    • pcre2

安装方法:brew

brew install gccbrew install xzbrew install pcre2
  • make之前需要安装
    • JDK:直接下载dmg安装
    • Mactex(可选):直接下载dmg安装或者brew cask install mactex

正文

起因

在R3.6.3下安装"psych"包,发现其依赖包‘mnormt’只支持R4.0以上。

> install.packages("psych")Warning in install.packages :  dependency ‘mnormt’ is not available  There is a binary version available but the source version is later:         binary source needs_compilationpsych 1.9.12.31  2.0.7             FALSEinstalling the source package ‘psych’trying URL 'https://cran.rstudio.com/src/contrib/psych_2.0.7.tar.gz'Content type 'application/x-gzip' length 1743492 bytes (1.7 MB)==================================================downloaded 1.7 MBERROR: dependency ‘mnormt’ is not available for package ‘psych’* removing ‘/Library/Frameworks/R.framework/Versions/3.6/Resources/library/psych’Warning in install.packages :  installation of package ‘psych’ had non-zero exit statusThe downloaded source packages are in	‘/private/var/folders/2m/m8nlj_2521d01sz7vypnvh940000gn/T/RtmpqaVH0v/downloaded_packages’

641d44b371de47142d5ce4269679ee3c.png

但是在mac下,安装R的pkg似乎没有办法使得两个版本的R并存。于是开始了我漫长的R4.0源码安装之旅。

从R4.0的下载和安装开始,逐渐走向不归路。

# 进入你常用的软件下载路径。我这里是srccd src# 下载wget https://cran.r-project.org/src/base/R-4/R-4.0.2.tar.gz# 解压tar -zxvf tar -zxvf R-4.0.2.tar.gzcd R-4.0.2# 查看configure的设置参数可以用下边命令# ./configure -h# 正式configure./configure --prefix=$HOME/opt --with-x=no --enable-R-shlib
  • --enable-R-shlib:build the shared/dynamic library 'libR' [no],要使底层R共享库对RStudio服务器可用,需要enable-R-shlib选项。
  • --with-x: use the X Window System

结果报错了:

checking whether we are using the GNU Fortran compiler... nochecking whether  accepts -g... noconfigure: error: No Fortran compiler found

安装gfortran

$ brew search gfortranWarning: Error searching on GitHub: curl failed!   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                 Dload  Upload   Total   Spent    Left  Speed  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (7) Failed to connect to api.github.com port 443: Connection refusedGNU Fortran is part of the GCC formula:  brew install gcc

好的,GNU Fortran is part of the GCC formula,那我就根据提示安装GCC吧。

brew install gcc

再来一次:

./configure --prefix=$HOME/opt --with-x=no --enable-R-shlib# configure: error: "liblzma library and headers are required"

搜索了一下,发现是因为缺少了xz库。好吧,老老实实安装。

brew install xz

也可以到这:http://R.research.att.com/libs/下载安装。

  • 解决方法参考了这篇:《Install R with shared library in OSX - liblzma library missing》:https://stackoverflow.com/questions/40222371/install-r-with-shared-library-in-osx-liblzma-library-missing

不气馁,再来一次:

./configure --prefix=$HOME/opt --with-x=no --enable-R-shlib

新的报错

configure: error: PCRE2 library and headers are required, or use --with-pcre1 and PCRE >= 8.32 with UTF-8 support

在CRAN给的R安装指南《R Installation and Administration》章节《Essential-programs-and-libraries》(https://cran.r-project.org/doc/manuals/r-devel/R-admin.html#Essential-programs-and-libraries)里是这么描述的:

Either PCRE1 (version 8.32 or later, formerly known as just PCRE) or PCRE2 is required: PCRE2 is preferred and using PCRE1 requires configure option --with-pcre1. Only the 8-bit library and headers are needed if these are packaged separately. JIT support (optional) is desirable for the best performance. For PCRE2 >= 10.30 (which is desirable as matching has been re-written not to use recursion and the Unicode tables were updated to version 10)./configure --enable-jitsuffices. If building PCRE1 for use with R a suitable configure command might be./configure --enable-utf --enable-unicode-properties --enable-jit --disable-cppThe --enable-jit flag is supported for most common CPUs. (See also the comments for Solaris.)Some packages require the ‘Unicode properties’ which are optional for PCRE1: support for this and JIT can be checked at run-time by calling pcre_config().

PCRE有PCRE1和PCRE2两个版本。更建议使用PCRE2。好的。来装吧:

brew install pcre2
  • 附:关于pcre--enable-jit:《pcrejit man page》(https://www.pcre.org/original/doc/html/pcrejit.html)

再来一次:

./configure --prefix=$HOME/opt --with-x=no --enable-R-shlib

好像可以了。来编译试试:

make

提示需要安装JDK。

到这里https://www.oracle.com/java/technologies/javase-jdk14-downloads.html下载对应版本安装。我下载的是dmg版本:

3e936ebecad84e434718d42feb5881bc.png

好了。继续往前

make installmake install-info  # To install info and PDF versions of the manualsmake check

make check: 安装后的检测。会生成一个tests目录。(个人猜测)原理应该是比较R脚本出来的结果跟它理应出来的结果进行比较。

在'reg-packages.R'这一个检测中报错了。

running code in 'array-subset.R' ... OKrunning code in 'reg-tests-1a.R' ... OKrunning code in 'reg-tests-1b.R' ... OKrunning code in 'reg-tests-1c.R' ... OKrunning code in 'reg-tests-1d.R' ... OKrunning code in 'reg-tests-2.R' ... OK  comparing 'reg-tests-2.Rout' to './reg-tests-2.Rout.save' ... OKrunning code in 'reg-examples1.R' ... OKrunning code in 'reg-examples2.R' ... OKrunning code in 'reg-packages.R' ...make[3]: *** [reg-packages.Rout] Error 1make[2]: *** [test-Reg] Error 2make[1]: *** [test-all-basics] Error 1make: *** [check] Error 2

于是进入tests目录查看,有一个reg-packages.Rout.fail的文件。如果成功的则没有.fail的后缀。找到开始报错的地方:

* checking for file '/private/var/folders/2m/m8nlj_2521d01sz7vypnvh940000gn/T/RtmpBZTu1Y/Pkgs/exSexpr/DESCRIPTION' ... OK* preparing 'exSexpr':* checking DESCRIPTION meta-information ... OK* installing the package to process help pages* saving partial Rd database* building the PDF package manualHmm ... looks like a packageCreating pdf output from LaTeX ...Error: R CMD build failed (no tarball) for package exSexprIn addition: Warning message:In system(paste(Rcmd, "build --keep-empty-dirs", shQuote(dir)),  :  running command ''/Users/wangqingzhong/src/R-4.0.2/bin/R' CMD build --keep-empty-dirs '/private/var/folders/2m/m8nlj_2521d01sz7vypnvh940000gn/T/RtmpBZTu1Y/Pkgs/exSexpr'' had status 1Execution halted

似乎是因为缺少了latex无法生成pdf导致的。

于是安装mactex,安装成功后报错就解除了。

这里插一句,如果按照需要已经安装好了,但还是报同样的错误。可以试试make distclean后再重新configure:

make distclean./configure --prefix=$HOME/opt --with-x=no --enable-R-shlib
  • make distclean 除了清除可执行文件和目标文件外,把configure所产生的Makefile也清除掉。(参考:《./configure,make,make install的作用》:http://www.linuxidc.com/Linux/2011-02/32211.htm)
mactex的安装
  • 方式一:brew(速度太慢,我舍弃了),下边三选一。
#There are three versions of MacTeX.#Full installation:  brew cask install mactex#Full installation without bundled applications:  brew cask install mactex-no-gui#Minimal installation:  brew cask install basictex
  • 方式二:安装pkg,安装之后添加环境变量

下载mactex:http://tug.org/cgi-bin/mactex-download/MacTeX.pkg

$ echo 'export PATH=/usr/local/texlive/2020/bin/x86_64-darwin/:$PATH' >> ~/.bash_profile source ~/.bash_profile
  • /usr/local/texlive/2020/bin/x86_64-darwin/是你mactex的最后路径。如果不知道可以使用find命令自己查找一下。

重新check:该错误终于修复了。这样看来,对于日常并不需要将tex文件编译成pdf的人来说,其实这个问题可能不修复也没有太大关系。

make check# running code in 'reg-packages.R' ... OK# 也没有再出现新的错误了。

另外,其实缺少mactex这个问题再configure的步骤就已经可以看出来。在没有安装mactex的时候configure会出来两条warning:因为pdf文档需要从tex编译过来。

configure: WARNING: you cannot build PDF versions of the R manualsconfigure: WARNING: you cannot build PDF versions of vignettes and help pages

好了,最后,生成pdf文档(可选)

make pdf# 显示需要pdflatex,但是系统没有。# 但是我输入pdflatex是有的。# 重新configure试试。# make distclean# ./configure --prefix=$HOME/opt --with-x=no --enable-R-shlib# make# make install# make install-info # make check# make pdf

添加环境变量,为了按需开启,而非总覆盖之前的R 3.6,我没有写到bash_profile中。而是随便命名了另一个.bash_czr。需要用R4.0的时候source一下它即可。

touch $HOME/.bash_czrecho 'export PATH=/Users/wangqingzhong/opt/bin:$PATH' >> $HOME/.bash_czr# R包安装路径echo 'export R_LIBS=/Users/wangqingzhong/opt/lib/R/library' >> $HOME/.bash_czrsource $HOME/.bash_czr
关于进入R后有warning:
1: Setting LC_CTYPE failed, using "C"2: Setting LC_COLLATE failed, using "C"3: Setting LC_TIME failed, using "C"4: Setting LC_MESSAGES failed, using "C"5: Setting LC_PAPER failed, using "C"

解决参考的:《Setting locales in terminal resolved the issue for me. Open the terminal and》(https://stackoverflow.com/questions/9689104/installing-r-on-mac-warning-messages-setting-lc-ctype-failed-using-c)

  1. Check if locale settings are missing

    > localeLANG=LC_COLLATE="C"LC_CTYPE="UTF-8"LC_MESSAGES="C"LC_MONETARY="C"LC_NUMERIC="C"LC_TIME="C"LC_ALL=
  2. Edit ~/.profile or ~/.bashrc

    export LANG=en_US.UTF-8export LC_ALL=en_US.UTF-8
  3. Run . ~/.profile or . ~/.bashrc to read from the file.

  4. Open a new terminal window and check that the locales are properly set

    > localeLANG="en_US.UTF-8"LC_COLLATE="en_US.UTF-8"LC_CTYPE="en_US.UTF-8"LC_MESSAGES="en_US.UTF-8"LC_MONETARY="en_US.UTF-8"LC_NUMERIC="en_US.UTF-8"LC_TIME="en_US.UTF-8"LC_ALL="en_US.UTF-8"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值