无法在R中安装网状

时间:2020-02-22 20:57:18

标签: r xcode gcc tidyverse reticulate

我正在尝试安装网状结构,以便可以执行从R中编写的一些Python代码。不幸的是,我在安装软件包时遇到了麻烦,而且没有足够的运气来确定原因。

我发现它可能与编译程序包以及gcc或不同版本的c ++编译器可能存在的问题有关,但是我对这些问题有点儿不了解,因此无法使任何工作。我尝试卸载并重新安装xcode命令行工具,但这并不能解决问题。除此之外,我不确定从哪里开始。我希望有人能体验到这一点,并且有一个简单的答案,非常感谢您的帮助。

> install.packages('reticulate')

  There is a binary version available but the source version is later:
           binary source needs_compilation
reticulate   1.13   1.14              TRUE

Do you want to install from sources the package which needs compilation? (Yes/no/cancel) y
installing the source package ‘reticulate’

trying URL 'https://cran.rstudio.com/src/contrib/reticulate_1.14.tar.gz'
Content type 'application/x-gzip' length 1504849 bytes (1.4 MB)
==================================================
downloaded 1.4 MB

* installing *source* package ‘reticulate’ ...
** package ‘reticulate’ successfully unpacked and MD5 sums checked
** libs
/usr/local/bin/gcc-8  -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c RcppExports.cpp -o RcppExports.o
/usr/local/bin/gcc-8  -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c event_loop.cpp -o event_loop.o
/usr/local/bin/gcc-8  -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c libpython.cpp -o libpython.o
/usr/local/bin/gcc-8  -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c output.cpp -o output.o
/usr/local/bin/gcc-8  -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c python.cpp -o python.o
/usr/local/bin/gcc-8  -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include   -fPIC  -Wall -g -O2  -c readline.cpp -o readline.o
/usr/local/bin/gcc-8 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o reticulate.so RcppExports.o event_loop.o libpython.o output.o python.o readline.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
installing to /Library/Frameworks/R.framework/Versions/3.5/Resources/library/reticulate/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
Error: package or namespace load failed for ‘reticulate’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/Library/Frameworks/R.framework/Versions/3.5/Resources/library/reticulate/libs/reticulate.so':
  dlopen(/Library/Frameworks/R.framework/Versions/3.5/Resources/library/reticulate/libs/reticulate.so, 6): Symbol not found: __ZNSt15basic_streambufIcSt11char_traitsIcEE5imbueERKSt6locale
  Referenced from: /Library/Frameworks/R.framework/Versions/3.5/Resources/library/reticulate/libs/reticulate.so
  Expected in: flat namespace
 in /Library/Frameworks/R.framework/Versions/3.5/Resources/library/reticulate/libs/reticulate.so
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/reticulate’
Warning in install.packages :
  installation of package ‘reticulate’ had non-zero exit status

The downloaded source packages are in
    ‘/private/var/folders/4g/ctbqp07114x4brzp4hr8zfc40000gn/T/RtmpDNvElq/downloaded_packages’

会话信息:

> sessionInfo()
R version 3.5.3 (2019-03-11)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS  10.15.2

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_3.5.3 tools_3.5.3    yaml_2.2.0  

1 个答案:

答案 0 :(得分:0)

好的,我建议使用conda创建一个新环境并在那里重新安装。因为那样您就可以解决问题-因为只有一行conda install -c conda-forge r-reticulate会为您解决所有问题,所以您可以安装网状网格和基于r的解决方案。

但是有些人(不知道conda是什么)对我的建议不满意。我不能也不会帮助他们。

但是对于那些知道conda的人,我建议:

conda create --name R_reticulate
source activate R_reticulate

conda install -c conda-forge r-reticulate

(或者您当然可以在安装到conda环境中时确定版本号...)

如果本地环境中R的版本现在与全局R相同,则您甚至可以覆盖已存在的R中安装的大多数库-因此您不必重新安装它们。只需在conda env的R中操作path变量即可。

(就像一个黑客一样,如果您懒于重新安装所有内容,可能是因为您只想先使用网状结构,然后再将其安装到全局R中)。

为此,在全局R控制台中,通过.libPaths()确定全局R控制台的安装位置。

然后在R_reticulate conda环境中启动R, 在会话开始时

my_libPaths <- .libPaths()
# and e.g. add one or some of your global .libPaths() paths
# to here by
my_libPaths <- <- c(my_libPaths, one_of_global_path)
.libPaths(my_libPaths) # assign new libpaths! 
# the order of the paths in the vector is important - decides about where R looks first!
# of course you can change order like you want in the vector!

那样,您不必重新安装库。

但是,全局和本地(conda)R的版本号必须相同,这样才能起作用。 否则,在加载库时,您将始终收到警告...

当然,简单的方法是将所有内容重新安装到conda env的R中(conda可以为您提供很多帮助!)。