![](/img/trans.png)
[英]Cannot load R package gmm on newest macbook with Apple M1 chip
[英]Installing gfortran on MacBook with Apple M1 chip for use in R
我在一台裝有 Apple M1 芯片的 MacBook Air 上,使用 macOS 11.6 Big Sur。 我在 R 4.1.1 上。 我為 Apple M1 安裝了 Xtools 和 gfortran :
markwhite@marks-air ~ % which xcode-select
/usr/bin/xcode-select
markwhite@marks-air ~ % which gfortran
/usr/local/bin/gfortran
我能夠成功安裝和運行 R,但安裝一些軟件包給我帶來了麻煩:
> install.packages("mvtnorm")
There is a binary version available but the source version is later:
binary source needs_compilation
mvtnorm 1.1-2 1.1-3 TRUE
Do you want to install from sources the package which needs compilation? (Yes/no/cancel) Yes
installing the source package ‘mvtnorm’
trying URL 'https://cran.rstudio.com/src/contrib/mvtnorm_1.1-3.tar.gz'
Content type 'application/x-gzip' length 166421 bytes (162 KB)
==================================================
downloaded 162 KB
* installing *source* package ‘mvtnorm’ ...
** package ‘mvtnorm’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/opt/R/arm64/include -fPIC -falign-functions=64 -Wall -g -O2 -c C_FORTRAN_interface.c -o C_FORTRAN_interface.o
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/opt/R/arm64/include -fPIC -falign-functions=64 -Wall -g -O2 -c miwa.c -o miwa.o
/opt/R/arm64/bin/gfortran -mtune=native -fno-optimize-sibling-calls -fPIC -Wall -g -O2 -c mvt.f -o mvt.o
make: /opt/R/arm64/bin/gfortran: No such file or directory
make: *** [mvt.o] Error 1
ERROR: compilation failed for package ‘mvtnorm’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/mvtnorm’
Warning in install.packages :
installation of package ‘mvtnorm’ had non-zero exit status
The downloaded source packages are in
‘/private/var/folders/fx/f46lfqf56_df59fvzgqhcbyr0000gn/T/RtmpfGZUAF/downloaded_packages’
>
我相信關鍵是: make: /opt/R/arm64/bin/gfortran: No such file or directory
,它在錯誤的位置尋找 gfortran。
確認它不存在:
markwhite@marks-air ~ % cd /opt/R/arm64/
markwhite@marks-air arm64 % ls -la
total 0
drwxrwxr-x 8 root wheel 256 Oct 18 11:04 .
drwxrwxr-x 3 root wheel 96 May 13 20:40 ..
drwxrwxr-x 14 root wheel 448 Oct 19 21:34 bin
drwxrwxr-x 29 root wheel 928 May 13 20:47 include
drwxrwxr-x 20 root wheel 640 May 14 18:50 lib
drwxrwxr-x 5 root wheel 160 May 13 20:40 man
drwxr-xr-x 3 root wheel 96 May 14 18:28 pkg
drwxrwxr-x 5 root wheel 160 Oct 18 11:04 share
markwhite@marks-air arm64 %
所以,我只是將 gfortran 從它所在的位置移動到 R 想要的位置:
markwhite@marks-air gfortran % sudo mv /usr/local/bin/gfortran /opt/R/arm64/bin
Password:
markwhite@marks-air gfortran %
然后,我重新啟動 R 並重試:
> install.packages("mvtnorm")
There is a binary version available but the source version is later:
binary source needs_compilation
mvtnorm 1.1-2 1.1-3 TRUE
Do you want to install from sources the package which needs compilation? (Yes/no/cancel) Yes
installing the source package ‘mvtnorm’
trying URL 'https://cran.rstudio.com/src/contrib/mvtnorm_1.1-3.tar.gz'
Content type 'application/x-gzip' length 166421 bytes (162 KB)
==================================================
downloaded 162 KB
* installing *source* package ‘mvtnorm’ ...
** package ‘mvtnorm’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/opt/R/arm64/include -fPIC -falign-functions=64 -Wall -g -O2 -c C_FORTRAN_interface.c -o C_FORTRAN_interface.o
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/opt/R/arm64/include -fPIC -falign-functions=64 -Wall -g -O2 -c miwa.c -o miwa.o
/opt/R/arm64/bin/gfortran -mtune=native -fno-optimize-sibling-calls -fPIC -Wall -g -O2 -c mvt.f -o mvt.o
mvt.f:861:11:
861 | hs = sign( one, dh - r*dk )
| 1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
mvt.f:862:11:
862 | ks = sign( one, dk - r*dh )
| 1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
mvt.f:1155:16:
1155 | K = MOD( C(NP, MIN(NDIM-1,KLIM-1))*DBLE(K), DBLE(P(NP)) )
| 1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
mvt.f:1215:17:
1215 | JP = 1 + J*R(J)
| 1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
mvt.f:94:39:
94 | DOUBLE PRECISION COV(NL*(NL+1)/2), A(NL), B(NL), DL(NL), Y(NL)
| 1
Warning: Array ‘cov’ at (1) is larger than limit set by ‘-fmax-stack-var-size=’, moved from stack to static storage. This makes the procedure unsafe when called recursively, or concurrently from multiple threads. Consider using ‘-frecursive’, or increase the ‘-fmax-stack-var-size=’ limit, or change the code to use an ALLOCATABLE array. [-Wsurprising]
mvt.f:86:33:
86 | SUBROUTINE MVSUBR( N, W, NF, F )
| 1
Warning: Unused dummy argument ‘nf’ at (1) [-Wunused-dummy-argument]
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/opt/R/arm64/include -fPIC -falign-functions=64 -Wall -g -O2 -c mvtnorm-init.c -o mvtnorm-init.o
/opt/R/arm64/bin/gfortran -mtune=native -fno-optimize-sibling-calls -fPIC -Wall -g -O2 -c tvpack.f -o tvpack.o
tvpack.f:395:14:
395 | HS = SIGN( ONE, DH - R*DK )
| 1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
tvpack.f:396:14:
396 | KS = SIGN( ONE, DK - R*DH )
| 1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
tvpack.f:60:52:
60 | DOUBLE PRECISION ONE, ZRO, EPS, ZROS(3), HS(3), TVT, TVTL
| 1
Warning: Unused variable ‘hs’ declared at (1) [-Wunused-variable]
tvpack.f:60:45:
60 | DOUBLE PRECISION ONE, ZRO, EPS, ZROS(3), HS(3), TVT, TVTL
| 1
Warning: Unused variable ‘zros’ declared at (1) [-Wunused-variable]
tvpack.f:220:72:
220 | END
| ^
Warning: ‘fin’ may be used uninitialized in this function [-Wmaybe-uninitialized]
tvpack.f:196:58:
196 | DOUBLE PRECISION EI(NL), AI(NL), BI(NL), FI(NL), FIN, ERR, KRNRDT
| ^
note: ‘fin’ was declared here
clang -arch arm64 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/opt/R/arm64/lib -o mvtnorm.so C_FORTRAN_interface.o miwa.o mvt.o mvtnorm-init.o tvpack.o -L/opt/R/arm64/gfortran/lib/gcc/aarch64-apple-darwin20.2.0/11.0.0 -L/opt/R/arm64/gfortran/lib -lgfortran -lemutls_w -lm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: warning: directory not found for option '-L/opt/R/arm64/gfortran/lib/gcc/aarch64-apple-darwin20.2.0/11.0.0'
ld: warning: directory not found for option '-L/opt/R/arm64/gfortran/lib'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mvtnorm.so] Error 1
ERROR: compilation failed for package ‘mvtnorm’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/mvtnorm’
Warning in install.packages :
installation of package ‘mvtnorm’ had non-zero exit status
The downloaded source packages are in
‘/private/var/folders/fx/f46lfqf56_df59fvzgqhcbyr0000gn/T/RtmpmlhiE8/downloaded_packages’
>
看起來它仍然與目錄路徑混淆,或者mv
實際上並沒有移動它需要移動的東西。
如何將 R 指向正確的目錄或將 gfortran 安裝在正確的目錄中?
我知道這個問題現在很混亂,我查看了其他線程,但無法完全得到任何人建議的工作。
我刪除了所有與 gfortran 相關的內容並重新開始。
我使用瀏覽器在此處下載了 .tar.xz 文件,該瀏覽器將文件轉儲到了我的下載文件夾中。 我雙擊它來解壓它。
我將該目錄移動到 R 想要的位置:
markwhite@marks-air ~ % sudo mv Downloads/gfortran /opt/R/arm64/
然后我重新啟動 R 並再次嘗試。 它向我拋出了一些 Fortran 編譯消息——我不會在這里假裝理解——但它成功安裝了:
> install.packages("mvtnorm")
There is a binary version available but the source version is later:
binary source needs_compilation
mvtnorm 1.1-2 1.1-3 TRUE
Do you want to install from sources the package which needs compilation? (Yes/no/cancel) Yes
installing the source package ‘mvtnorm’
trying URL 'https://cran.rstudio.com/src/contrib/mvtnorm_1.1-3.tar.gz'
Content type 'application/x-gzip' length 166421 bytes (162 KB)
==================================================
downloaded 162 KB
* installing *source* package ‘mvtnorm’ ...
** package ‘mvtnorm’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/opt/R/arm64/include -fPIC -falign-functions=64 -Wall -g -O2 -c C_FORTRAN_interface.c -o C_FORTRAN_interface.o
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/opt/R/arm64/include -fPIC -falign-functions=64 -Wall -g -O2 -c miwa.c -o miwa.o
/opt/R/arm64/bin/gfortran -mtune=native -fno-optimize-sibling-calls -fPIC -Wall -g -O2 -c mvt.f -o mvt.o
mvt.f:861:11:
861 | hs = sign( one, dh - r*dk )
| 1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
mvt.f:862:11:
862 | ks = sign( one, dk - r*dh )
| 1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
mvt.f:1155:16:
1155 | K = MOD( C(NP, MIN(NDIM-1,KLIM-1))*DBLE(K), DBLE(P(NP)) )
| 1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
mvt.f:1215:17:
1215 | JP = 1 + J*R(J)
| 1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
mvt.f:94:39:
94 | DOUBLE PRECISION COV(NL*(NL+1)/2), A(NL), B(NL), DL(NL), Y(NL)
| 1
Warning: Array ‘cov’ at (1) is larger than limit set by ‘-fmax-stack-var-size=’, moved from stack to static storage. This makes the procedure unsafe when called recursively, or concurrently from multiple threads. Consider using ‘-frecursive’, or increase the ‘-fmax-stack-var-size=’ limit, or change the code to use an ALLOCATABLE array. [-Wsurprising]
mvt.f:86:33:
86 | SUBROUTINE MVSUBR( N, W, NF, F )
| 1
Warning: Unused dummy argument ‘nf’ at (1) [-Wunused-dummy-argument]
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/opt/R/arm64/include -fPIC -falign-functions=64 -Wall -g -O2 -c mvtnorm-init.c -o mvtnorm-init.o
/opt/R/arm64/bin/gfortran -mtune=native -fno-optimize-sibling-calls -fPIC -Wall -g -O2 -c tvpack.f -o tvpack.o
tvpack.f:395:14:
395 | HS = SIGN( ONE, DH - R*DK )
| 1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
tvpack.f:396:14:
396 | KS = SIGN( ONE, DK - R*DH )
| 1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
tvpack.f:60:52:
60 | DOUBLE PRECISION ONE, ZRO, EPS, ZROS(3), HS(3), TVT, TVTL
| 1
Warning: Unused variable ‘hs’ declared at (1) [-Wunused-variable]
tvpack.f:60:45:
60 | DOUBLE PRECISION ONE, ZRO, EPS, ZROS(3), HS(3), TVT, TVTL
| 1
Warning: Unused variable ‘zros’ declared at (1) [-Wunused-variable]
tvpack.f:220:72:
220 | END
| ^
Warning: ‘fin’ may be used uninitialized in this function [-Wmaybe-uninitialized]
tvpack.f:196:58:
196 | DOUBLE PRECISION EI(NL), AI(NL), BI(NL), FI(NL), FIN, ERR, KRNRDT
| ^
note: ‘fin’ was declared here
clang -arch arm64 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/opt/R/arm64/lib -o mvtnorm.so C_FORTRAN_interface.o miwa.o mvt.o mvtnorm-init.o tvpack.o -L/opt/R/arm64/gfortran/lib/gcc/aarch64-apple-darwin20.2.0/11.0.0 -L/opt/R/arm64/gfortran/lib -lgfortran -lemutls_w -lm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: warning: could not create compact unwind for _mvkrsv_: register 75 saved somewhere other than in frame
ld: warning: could not create compact unwind for _mvkbrv_: stack size is too large for frameless function
ld: warning: could not create compact unwind for _mvstdt_: register 75 saved somewhere other than in frame
ld: warning: could not create compact unwind for _mvbvtl_: registers 78 and 79 not saved contiguously in frame
ld: warning: could not create compact unwind for _pntgnd_: registers 72 and 73 not saved contiguously in frame
ld: warning: could not create compact unwind for _mvbvu_: registers 72 and 73 not saved contiguously in frame
ld: warning: could not create compact unwind for _tvtmfn_: register 73 saved somewhere other than in frame
ld: warning: could not create compact unwind for _krnrdt_: registers 74 and 75 not saved contiguously in frame
ld: warning: could not create compact unwind for _mvbvn_: registers 21 and 22 not saved contiguously in frame
ld: warning: could not create compact unwind for _bvnd_: registers 78 and 79 not saved contiguously in frame
ld: warning: could not create compact unwind for _bvtl_: registers 78 and 79 not saved contiguously in frame
ld: warning: could not create compact unwind for _tvtlrcall_: registers 72 and 73 not saved contiguously in frame
ld: warning: could not create compact unwind for _mvbvt_: registers 21 and 22 not saved contiguously in frame
ld: warning: could not create compact unwind for _mvspcl_: register 73 saved somewhere other than in frame
ld: warning: could not create compact unwind for _mvsort_: register 77 saved somewhere other than in frame
ld: warning: could not create compact unwind for _mvvlsb_: registers 27 and 28 not saved contiguously in frame
ld: warning: could not create compact unwind for _mvtdst_: registers 23 and 24 not saved contiguously in frame
ld: warning: could not create compact unwind for _mvbvtc_: register 73 saved somewhere other than in frame
installing to /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/00LOCK-mvtnorm/00new/mvtnorm/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (mvtnorm)
The downloaded source packages are in
‘/private/var/folders/fx/f46lfqf56_df59fvzgqhcbyr0000gn/T/RtmptXzvKK/downloaded_packages’
您是否嘗試對問題回答“否”:
Do you want to install from sources the package which needs compilation? (Yes/no/cancel)
?
除非您確實需要嘗試下載的軟件包的最新版本,否則它似乎可以正常工作,而無需像您那樣在指定的文件夾中安裝 gfortran。
我在安裝其他軟件包時遇到了類似的問題,但我嘗試做以下選擇,它允許我繼續:
Update all/some/none? [a/s/n]:
n
嘗試從源代碼安裝軟件包時遇到了類似的問題。 我的解決方案是
安裝 gcc 的 Homebrew 版本(包括 gfortran)
釀造安裝 gcc
告訴 R 它應該在哪里查找 gfortran 此信息存儲在文件“Makeconf”中,在我的情況下可以在此處找到:/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/etc/Makeconf
在“Makeconf”中更改該行
FLIBS = -L/Volumes/Builds/opt/R/arm64/gfortran/lib/gcc/aarch64-apple-darwin20.2.0/11.0.0 -L/Volumes/Builds/opt/R/arm64/gfortran/lib/gcc -L/Volumes/Builds/opt/R/arm64/gfortran/lib -lgfortran -lemutls_w -lm
至
FLIBS = -L/opt/homebrew/Cellar/gcc/11.3.0/lib/gcc/11/gcc/aarch64-apple-darwin21/11 -L/opt/homebrew/Cellar/gcc/11.3.0/lib/gcc/11 -lgfortran -lquadmath -lm
您可能需要根據系統上安裝的 gcc 版本來調整路徑。
這是在 Mac OS M1 系統上對我有用的方法。 R 版本 4.2.1(從這里的解決方案修改,可能適用於英特爾 Mac)
使用brew install gcc
創建一個文件~/.R/Makevars
(如果它還不存在)。 例如,請參見此處。
將以下行添加到~/.R/Makevars
FC = /opt/homebrew/Cellar/gcc/11.3.0_2/bin/gfortran
F77 = /opt/homebrew/Cellar/gcc/11.3.0_2/bin/gfortran
FLIBS = -L/opt/homebrew/Cellar/gcc/11.3.0_2/lib/gcc/11
請注意,您可能必須將 gcc 版本11.3.0_2
更改為您的 gcc 版本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.