Installation problem on MacOS Catalina (10.15.7)

Hi all!

I’ve played around with cmdstan in the past and was able to compile models back then, but I’m new to rstan. I upgraded my Mac OS X to Catalina (10.15.7) recently and have been struggling to get rstan to work. When I try the example following the instructions here, I get the following error:

> example(stan_model, package = "rstan", run.dontrun = TRUE)
[...]
Error in dyn.load(libLFile) :
  unable to load shared object '/var/folders/_8/0q_m6cvn03xg4x7f5fcfjxym0000gn/T//RtmpjjVEvv/file359b71949fd2.so':
  dlopen(/var/folders/_8/0q_m6cvn03xg4x7f5fcfjxym0000gn/T//RtmpjjVEvv/file359b71949fd2.so, 6): Symbol not found: __ZN5rstan8stan_fitC1EP7SEXPRECi
  Referenced from: /var/folders/_8/0q_m6cvn03xg4x7f5fcfjxym0000gn/T//RtmpjjVEvv/file359b71949fd2.so
  Expected in: flat namespace
 in /var/folders/_8/0q_m6cvn03xg4x7f5fcfjxym0000gn/T//RtmpjjVEvv/file359b71949fd2.so
  • Operating System: macOS Catalina - version 10.15.7 (19H2)
  • RStan Version - 2.21.2
  • Output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars"))) - This try was without a Makevars file, but setting up a Makevars as here gave the same result
  • Output of devtools::session_info("rstan") - below

I’ll add some other setup:

I installed XCode 12.4 (12D4e) and the corresponding Command Line Tools (xcode-select --version returns “version 2373”) through Apple.

I installed R 4.0.3 via this site, XQuartz 2.7.11 via this site, and MacOS RTools 4.0.0 from this site.

I have installed, uninstalled, and bounced R many times to try and get this working. Most recently, I removed three packages:

remove.packages(c("Rcpp", "StanHeaders", "rstan"))
if (file.exists(".RData")) file.remove(".RData")

Then I restarted my computer and installed them again from source:

Sys.setenv(MAKEFLAGS = paste0("-j",parallel::detectCores()))
install.packages(c("Rcpp", "StanHeaders", "rstan"), type = "source")

Same error as always, as shown above.

Thanks so much!


> devtools::session_info("rstan")
─ Session info ───────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.0.3 (2020-10-10)
 os       macOS Catalina 10.15.7
 system   x86_64, darwin17.0
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       America/New_York
 date     2021-01-27

─ Packages ───────────────────────────────────────────────────────────────────
 package      * version   date       lib source
 assertthat     0.2.1     2019-03-21 [1] CRAN (R 4.0.2)
 backports      1.2.1     2020-12-09 [1] CRAN (R 4.0.2)
 BH             1.75.0-0  2021-01-11 [1] CRAN (R 4.0.2)
 brio           1.1.1     2021-01-20 [1] CRAN (R 4.0.2)
 callr          3.5.1     2020-10-13 [1] CRAN (R 4.0.2)
 checkmate      2.0.0     2020-02-06 [1] CRAN (R 4.0.2)
 cli            2.2.0     2020-11-20 [1] CRAN (R 4.0.2)
 colorspace     2.0-0     2020-11-11 [1] CRAN (R 4.0.2)
 crayon         1.3.4     2017-09-16 [1] CRAN (R 4.0.2)
 curl           4.3       2019-12-02 [1] CRAN (R 4.0.1)
 desc           1.2.0     2018-05-01 [1] CRAN (R 4.0.2)
 diffobj        0.3.3     2021-01-07 [1] CRAN (R 4.0.2)
 digest         0.6.27    2020-10-24 [1] CRAN (R 4.0.2)
 ellipsis       0.3.1     2020-05-15 [1] CRAN (R 4.0.2)
 evaluate       0.14      2019-05-28 [1] CRAN (R 4.0.1)
 fansi          0.4.2     2021-01-15 [1] CRAN (R 4.0.2)
 farver         2.0.3     2020-01-16 [1] CRAN (R 4.0.2)
 ggplot2        3.3.3     2020-12-30 [1] CRAN (R 4.0.2)
 glue           1.4.2     2020-08-27 [1] CRAN (R 4.0.2)
 gridExtra      2.3       2017-09-09 [1] CRAN (R 4.0.2)
 gtable         0.3.0     2019-03-25 [1] CRAN (R 4.0.2)
 inline         0.3.17    2020-12-01 [1] CRAN (R 4.0.2)
 isoband        0.2.3     2020-12-01 [1] CRAN (R 4.0.2)
 jsonlite       1.7.2     2020-12-09 [1] CRAN (R 4.0.2)
 labeling       0.4.2     2020-10-20 [1] CRAN (R 4.0.2)
 lattice        0.20-41   2020-04-02 [1] CRAN (R 4.0.3)
 lifecycle      0.2.0     2020-03-06 [1] CRAN (R 4.0.2)
 loo            2.4.1     2020-12-09 [1] CRAN (R 4.0.2)
 magrittr       2.0.1     2020-11-17 [1] CRAN (R 4.0.2)
 MASS           7.3-53    2020-09-09 [1] CRAN (R 4.0.3)
 Matrix         1.2-18    2019-11-27 [1] CRAN (R 4.0.3)
 matrixStats    0.57.0    2020-09-25 [1] CRAN (R 4.0.2)
 mgcv           1.8-33    2020-08-27 [1] CRAN (R 4.0.3)
 munsell        0.5.0     2018-06-12 [1] CRAN (R 4.0.2)
 nlme           3.1-149   2020-08-23 [1] CRAN (R 4.0.3)
 pillar         1.4.7     2020-11-20 [1] CRAN (R 4.0.2)
 pkgbuild       1.2.0     2020-12-15 [1] CRAN (R 4.0.2)
 pkgconfig      2.0.3     2019-09-22 [1] CRAN (R 4.0.2)
 pkgload        1.1.0     2020-05-29 [1] CRAN (R 4.0.2)
 praise         1.0.0     2015-08-11 [1] CRAN (R 4.0.2)
 prettyunits    1.1.1     2020-01-24 [1] CRAN (R 4.0.2)
 processx       3.4.5     2020-11-30 [1] CRAN (R 4.0.2)
 ps             1.5.0     2020-12-05 [1] CRAN (R 4.0.2)
 R6             2.5.0     2020-10-28 [1] CRAN (R 4.0.2)
 RColorBrewer   1.1-2     2014-12-07 [1] CRAN (R 4.0.2)
 Rcpp           1.0.6     2021-01-15 [1] CRAN (R 4.0.3)
 RcppEigen      0.3.3.9.1 2020-12-17 [1] CRAN (R 4.0.2)
 RcppParallel   5.0.2     2020-06-24 [1] CRAN (R 4.0.2)
 rematch2       2.1.2     2020-05-01 [1] CRAN (R 4.0.2)
 rlang          0.4.10    2020-12-30 [1] CRAN (R 4.0.2)
 rprojroot      2.0.2     2020-11-15 [1] CRAN (R 4.0.2)
 rstan          2.21.2    2020-07-27 [1] CRAN (R 4.0.3)
 rstudioapi     0.13      2020-11-12 [1] CRAN (R 4.0.2)
 scales         1.1.1     2020-05-11 [1] CRAN (R 4.0.2)
 StanHeaders    2.21.0-7  2020-12-17 [1] CRAN (R 4.0.3)
 testthat       3.0.1     2020-12-17 [1] CRAN (R 4.0.2)
 tibble         3.0.5     2021-01-15 [1] CRAN (R 4.0.2)
 utf8           1.1.4     2018-05-24 [1] CRAN (R 4.0.2)
 V8             3.4.0     2020-11-04 [1] CRAN (R 4.0.2)
 vctrs          0.3.6     2020-12-17 [1] CRAN (R 4.0.2)
 viridisLite    0.3.0     2018-02-01 [1] CRAN (R 4.0.1)
 waldo          0.2.3     2020-11-09 [1] CRAN (R 4.0.2)
 withr          2.4.1     2021-01-26 [1] CRAN (R 4.0.3)

[1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library

Hi, is there a reason you want to use rstan instead of cmdstan?

Yes - I’ve organized a reading group, currently underway, working through Statistical Rethinking by Richard McElreath. This text embeds rstan within its toolchain. To follow the text, my best options are either to get rstan working or to use one of the repos in which McElreath has been translated into technologies outside of Stan (such as pymc3).

is there a specific repo for McElreath in pymc3 you prefer?

Yes - this is the one which was recommended to me and which looks good from a brief perusal: resources/Rethinking at master · pymc-devs/resources · GitHub

1 Like

You know that you can use cmdstan with rethinking using cmdstan=TRUE in ulam()?

1 Like

I didn’t know that! Thanks much - this may be how I work around this issue (assuming I can get cmdstan to work with my OS as currently updated and configured - I may try that next).

Based on this conversation, I think I might be missing some context. Is rstan deprecated software?

No not at all, but cmdstan is moving a bit more quickly and rstan always needs to be added to CRAN, which can make things lag a bit… Use cmdstanr to install cmdstan.

OK, that’s super useful context. Thanks much! I will give this a whirl and update with what I find for the benefit of future people who want to study McElreath on a Mac.

Please have a look at the readme under Quick Installation:

Thanks again, Mitzi and Richard! I know this thread is ancient, but responding to this never left my “Action” folder…2021 has just been a bit of a year. I finally worked through this!

It worked swimmingly to use cmdstanr with the McElreath book. For posterity, I did some installations within the R REPL (in RStudio):

devtools::install_github("stan-dev/cmdstanr")
cmdstanr::install_cmdstan()

To use the tools, after pulling in the rethinking library, I patched in the cmdstanr backend as follows:

library(rethinking)
set_ulam_cmdstan(TRUE)

And then the examples/homework in the book ran as advertised.

Again, I appreciate your help!

2 Likes