How to install scikit-learn on heroku cedar?

Viewed 3497

I'v successfully installed numpy and scipy using the method described in this answer. Then I wanted to add scikit-learn so at first I tried adding scikit-learn==0.11 to the requirements.txt and when pushed to heroku I got an error message:

ImportError: liblapack.so.3gf: cannot open shared object file: No such file or directory

So I've added to LD_LIBRARY_PATH the path where I have liblapack.so.3gf but then I got this:

ImportError: libgfortran.so.3: cannot open shared object file: No such file or directory

I believe that heroku doesn't have fortran compiler, but maybe I wrong. How can I resolve this?

6 Answers

If you came here like me having issues while installing scikit learn and getting error,

ImportError: numpy is not installed.
scikit-learn requires numpy >= 1.11.0.

What you have to do is check the version of your local/dev environment and use that specific versions while deploying, even the python version.

Either use pip freeze as mentioned by zenpoy or following.

import scipy
import sklearn
import numpy

print(scipy.__version__)
print(sklearn.__version__)
print(numpy.__version__)

Add this versions specifically to requirements.txt

scipy==1.4.1
scikit-learn==0.22.2.post1
numpy==1.19.5

In heroku to set the Python runtime, add a runtime.txt file to your app’s root directory that declares the exact version number to use:

python-3.7.10
Related