Library not loaded: @rpath/libtbb.dylib in Prophet / Python
Asked Answered
F

3

7

I'm on a Mac X1, Monterey.

I've installed prophet and run into this issue when trying to fit a model.

RuntimeError: Error during optimization: console log output:

dyld[90668]: Library not loaded: @rpath/libtbb.dylib

Referenced from: /Users/{username}/opt/anaconda3/lib/python3.9/site-packages/prophet/stan_model/prophet_model.bin
  Reason: tried: '/private/var/folders/cd/dfrqgp4s4ll55cwb7rtgccbw0000gq/T/pip-install-rjpuj450/prophet_d7e4cce10e414c89a572fe3605ae9269/build/lib.macosx-11.1-arm64-cpython-39/prophet/stan_model/cmdstan-2.26.1/stan/lib/stan_math/lib/tbb/libtbb.dylib' (no such file), '/private/var/folders/cd/dfrqgp4s4ll55cwb7rtgccbw0000gq/T/pip-install-rjpuj450/prophet_d7e4cce10e414c89a572fe3605ae9269/build/lib.macosx-11.1-arm64-cpython-39/prophet/stan_model/cmdstan-2.26.1/stan/lib/stan_math/lib/tbb/libtbb.dylib' (no such file), '/usr/local/lib/libtbb.dylib' (no such file), '/usr/lib/libtbb.dylib' (no such file)

I know this has to do with the wrong paths being searched. I can find the dylib in

/Users/{user}/opt/anaconda3/lib/python3.9/site-packages/prophet/stan_model/cmdstan-2.26.1/stan/lib/stan_math/lib/tbb/

But, it seems prophet doesn't know to look there. I'm curious how I can update/fix either the rpath variable or find another solution?

I tried to create a symbolic link with sudo ln -s, but don't have permissions on the laptop.

TIA!

Flashback answered 5/8, 2022 at 20:52 Comment(0)
F
10

I got it to work on Apple Silicon (M1 Max in my case) by installing older versions of both pystan and prophet:

pip install pystan==2.19.1.1
pip install prophet==1.0

The other important piece of the puzzle is that you should use Python 3.8 to get it working.

Installing older versions of the libraries and using Python 3.8 are both talked about in issue #2002 on Github, but there's not really an explanation of the libtbb.dylib error message.

Footrace answered 7/8, 2022 at 15:14 Comment(2)
Thanks! This worked for me. I am on a Mac m1 air. I was missing a few other dependencies so had to install those before prophet. pip install tqdm, holidays==0.24 convertdate lunarcalendar pandasLauree
The comma is unnecessary, but I came to the same conclusion!Madison
C
7

I got it working on my Apple M2 Pro machine!

I had to fix 1 line after install and make 3 symlinks for not loaded libraries.

(Note: you may need to change the paths according to your system.)

conda create -n myenv python=3.9 pip
conda activate myenv
conda install numpy pandas plotly
pip install prophet
vim $HOME/miniconda3/envs/myenv/lib/python3.9/site-packages/holidays/registry.py

line 178 fix (resolves the error on library import):

#super().__init__(*args, **kwargs)
super().__init__()

and 3 symlinks

sudo mkdir /usr/local/lib
sudo ln -s $HOME/miniconda3/envs/myenv/lib/python3.9/site-packages/prophet/stan_model/cmdstan-2.26.1/stan/lib/stan_math/lib/tbb/libtbb.dylib /usr/local/lib/libtbb.dylib
sudo ln -s $HOME/miniconda3/envs/myenv/lib/python3.9/site-packages/prophet/stan_model/cmdstan-2.26.1/stan/lib/stan_math/lib/tbb/libtbbmalloc.dylib /usr/local/lib/libtbbmalloc.dylib
sudo ln -s $HOME/miniconda3/envs/myenv/lib/python3.9/site-packages/prophet/stan_model/cmdstan-2.26.1/stan/lib/stan_math/lib/tbb/libtbbmalloc_proxy.dylib /usr/local/lib/libtbbmalloc_proxy.dylib

test the installation:

import pandas as pd
from prophet import Prophet
df = pd.read_csv('https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_peyton_manning.csv')
m = Prophet()
m.fit(df)
future = m.make_future_dataframe(periods=365)
forecast = m.predict(future)
forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail()
Conditioner answered 16/5, 2023 at 14:31 Comment(2)
Man, how come they still haven't fixed it in prophet? The issue has been open since May.Madison
There is no issues in installation with this followed. However, m.fit(df) won't work.Muoimuon
O
4

I found a fix that should be prophet version agnostic. What's happening is that prophet is looking for the libtbb library in all the various paths referenced by rpath. For whatever reason, the actual path where the library was installed is not in rpath. Here's how to fix it.

  1. Locate the libtbb library on your machine (prophet versions above 1.0 actually install the library within the prophet package folder as part of the installation, but the referenced path is not working).

1a. If you can't locate the library, you can install cmdstan in a location of your choosing by using the following (from Python):

>>> import cmdstanpy
>>> cmdstanpy.install_cmdstan(overwrite=True, compiler=True, dir=<path/to/cmdstan>)

path/to/cmdstan is your chosen folder. More info here.

  1. Add the path to libtbb library (inside the cmdstan folder) to your rpath variable and push it to the prophet_model.bin file, so prophet knows where to look (from bash):

First, cd into the folder within the prophet package that contains prophet_model.bin then run the following command

% install_name_tool -add_rpath /path/to/cmdstan/stan/lib/stan_math/lib/tbb prophet_model.bin

Note that I added stan/lib/stan_math/lib/tbb to the /path/to/cmdstan/ you set. That's where the libtbb library sits.

That's it! Should run without giving up on the latest version of this great package.

Overstay answered 7/3, 2023 at 22:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.