rstan icon indicating copy to clipboard operation
rstan copied to clipboard

Failing to load libtbbmalloc.2.dylib

Open neurotroph opened this issue 3 years ago • 5 comments

Summary:

In a fresh installation of rstan, linking the libtbbmalloc.2.dylib fails when running the example code.

Description:

A couple of months ago I had a project involving Rstan running smoothly. Returning now, I come across the error stated below. I have uninstalled Rstan, made sure that all dependencies and tool chains are properly installed, and reinstalled Rstan. The problem persists: when using the test code from the Getting Started guide

example(stan_model, package = "rstan", run.dontrun = TRUE)

I receive the error:

Error in dyn.load(libLFile) : 
  unable to load shared object '/var/folders/86/8s8l46dj1h12jrx1m71jkxtn0s352c/T//Rtmpz0AKh0/file6556344933ec.so':
  dlopen(/var/folders/86/8s8l46dj1h12jrx1m71jkxtn0s352c/T//Rtmpz0AKh0/file6556344933ec.so, 6): Library not loaded: @rpath/libtbbmalloc.2.dylib
  Referenced from: /usr/local/opt/tbb/lib/libtbbmalloc_proxy.2.dylib
  Reason: image not found

Package RcppParallel is installed (see session info below).

Reproducible Steps:

remove.packages('rstan')
# Restart R session
install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE)
example(stan_model, package = "rstan", run.dontrun = TRUE)

Current Output:

Error in dyn.load(libLFile) : 
  unable to load shared object '/var/folders/86/8s8l46dj1h12jrx1m71jkxtn0s352c/T//Rtmpz0AKh0/file6556344933ec.so':
  dlopen(/var/folders/86/8s8l46dj1h12jrx1m71jkxtn0s352c/T//Rtmpz0AKh0/file6556344933ec.so, 6): Library not loaded: @rpath/libtbbmalloc.2.dylib
  Referenced from: /usr/local/opt/tbb/lib/libtbbmalloc_proxy.2.dylib
  Reason: image not found

Expected Output:

A successfully sampled example model.

sessionInfo()

Includes package versions and operating system.

> sessionInfo()
R version 4.0.5 (2021-03-31)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 11.4

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/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     

other attached packages:
[1] rstan_2.21.2         ggplot2_3.3.3        StanHeaders_2.21.0-7

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.6         pillar_1.6.0       compiler_4.0.5     prettyunits_1.1.1  tools_4.0.5        pkgbuild_1.2.0     jsonlite_1.7.2    
 [8] lifecycle_1.0.0    tibble_3.1.1       gtable_0.3.0       pkgconfig_2.0.3    rlang_0.4.11       DBI_1.1.1          cli_2.5.0         
[15] parallel_4.0.5     curl_4.3.1         loo_2.4.1          gridExtra_2.3      withr_2.4.2        dplyr_1.0.5        generics_0.1.0    
[22] vctrs_0.3.8        stats4_4.0.5       grid_4.0.5         tidyselect_1.1.1   glue_1.4.2         inline_0.3.17      R6_2.5.0          
[29] processx_3.5.1     fansi_0.4.2        purrr_0.3.4        callr_3.6.0        magrittr_2.0.1     codetools_0.2-18   matrixStats_0.58.0
[36] scales_1.1.1       ps_1.6.0           ellipsis_0.3.2     assertthat_0.2.1   colorspace_2.0-0   V8_3.4.0           utf8_1.2.1        
[43] RcppParallel_5.1.4 munsell_0.5.0      crayon_1.4.1      

neurotroph avatar Jul 05 '21 15:07 neurotroph

To clarify some questions I came across when investigating this further:

tbb was installed through homebrew (Edit: Nevermind, RcppParallel bundles its own version.)

brew install tbb

and is installed to /usr/local/opt/tbb/, which I verified.

Adding the paths directly to ~/.R/Makevars by adding:

LDFLAGS += -L/usr/local/opt/tbb/lib
CPPFLAGS += -I/usr/local/opt/tbb/include

Resulted in no change.

neurotroph avatar Jul 06 '21 12:07 neurotroph

tbb was installed through homebrew

That was the problem. After completely removing the tbb installation through homebrew, rstan complies the model just fine.

I think, however, that this might be a bug if it is replicable -- a system-wide tbb might be required, e.g. because I have used igraph in the past, which requires tbb.

neurotroph avatar Jul 08 '21 06:07 neurotroph

I had the same issue and uninstalling tbb with homebrew fixed it.

jhrcook avatar Jul 15 '21 20:07 jhrcook

Same thing on my end. I got the exact same error as reported by @neurotroph when running

example(stan_model, package = "rstan", run.dontrun = TRUE)

Removing tbb with:

brew uninstall tbb

solved it for me. My sessionInfo() is:

R version 4.1.0 (2021-05-18)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

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

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

other attached packages:
[1] rstan_2.21.2         ggplot2_3.3.5        StanHeaders_2.21.0-7

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.7         pillar_1.6.1       compiler_4.1.0     prettyunits_1.1.1  pkgbuild_1.2.0     jsonlite_1.7.2     lifecycle_1.0.0    tibble_3.1.2       gtable_0.3.0      
[10] pkgconfig_2.0.3    rlang_0.4.11       DBI_1.1.1          cli_3.0.1          parallel_4.1.0     curl_4.3.2         loo_2.4.1          gridExtra_2.3      withr_2.4.2       
[19] dplyr_1.0.7        generics_0.1.0     vctrs_0.3.8        stats4_4.1.0       grid_4.1.0         tidyselect_1.1.1   glue_1.4.2         inline_0.3.19      R6_2.5.0          
[28] processx_3.5.2     fansi_0.5.0        purrr_0.3.4        callr_3.7.0        magrittr_2.0.1     codetools_0.2-18   matrixStats_0.59.0 scales_1.1.1       ps_1.6.0          
[37] ellipsis_0.3.2     assertthat_0.2.1   colorspace_2.0-2   V8_3.4.2           utf8_1.2.1         RcppParallel_5.1.4 munsell_0.5.0      crayon_1.4.1      

dbarneche avatar Jul 22 '21 04:07 dbarneche

Same here. I had to brew uninstall bowtie2 as well, though, since it relies on tbb. That's a pity because I need bowtie2 (but I can probably get it via conda). After the brew uninstall tbb in R I needed an uninstall.packages("brms") and then install.packages("brms").

Thanks @neurotroph !

terrycojones avatar Nov 06 '21 15:11 terrycojones