facebook / prophet

Tool for producing high quality forecasts for time series data that has multiple seasonality with linear or non-linear growth.
https://facebook.github.io/prophet
MIT License
18.46k stars 4.53k forks source link

Error: package or namespace load failed for ‘prophet’ in dyn.load(file, DLLpath = DLLpath, ...) #1628

Closed mdancho84 closed 4 years ago

mdancho84 commented 4 years ago

Great package. I have integrated into modeltime (R package that uses prophet with tidymodels ecosystem). It's working great.

I did run into one issue when using on MacOS (Windows I have not experienced this problem). I've referenced the issue business-science/modeltime#20.

Problem

MacOS seems to have an issue (sometimes???) when loading prophet.

> library(prophet)
Loading required package: Rcpp
Loading required package: rlang
Error: package or namespace load failed for ‘prophet’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/Library/Frameworks/R.framework/Versions/4.0/Resources/library/prophet/libs/prophet.so':
  dlopen(/Library/Frameworks/R.framework/Versions/4.0/Resources/library/prophet/libs/prophet.so, 6): Library not loaded: @rpath/libtbb.dylib
  Referenced from: /Library/Frameworks/R.framework/Versions/4.0/Resources/library/prophet/libs/prophet.so
  Reason: image not found

Solution

The easiest way to fix is to load StanHeaders. This sets the C++ flags and libraries, which seems to solve the missed libtbb.dylib path.

How I solved it with modeltime:

Add StanHeaders to Imports image

Somewhere in the package import StanHeaders.

image

The same solution will work for prophet.

bletham commented 4 years ago

Thanks for raising the issue. This issue actually cropped up for a few people recently (#1601, #1604, #1608). I haven't run into it myself so haven't been able to do much by way of thorough investigation, but in #1604 I wondered if it could be something with the model not compiling properly, so I recommended re-installing prophet from source, and that seemed to work in that case. #1608 also fixed it with package upgrades (of dependencies, but maybe prophet was re-installed as part of that?).

But to clarify one point: it seems that you added StanHeaders to the imports for the modeltime package and that fixed the error that was being raised when it imported prophet. Did you by chance try adding it directly to prophet to verify that fixes it? Once I replicate the error I could try that myself, but I'm not really sure of the source of the error. It'd be great to have a solution for this other than the re-install-from-source that seemed to work once.

mdancho84 commented 4 years ago

Hey Ben,

Yes - I can do this. I know it will work because I've been doing it manually:

library(StanHeaders)
library(prophet)

Works fine on my machine. And all StanHeaders does is generate the C++ bindings for Rcpp & Stan (so it's super lightweight).

I have a stacked schedule but hopefully by weekend I can send a PR addressing this.

bletham commented 4 years ago

Thanks! Great to know the workaround too.

mdancho84 commented 4 years ago

@bletham PR #1643 fixes this issue.

image

seanjtaylor commented 4 years ago

Oops I asked in the PR, but got the answer here. Nevermind!

mdancho84 commented 4 years ago

Hey @seanjtaylor & @bletham - I checked and this fixes the issues. Thanks for merging. I just had another student with the same issue.