heroku / heroku-geo-buildpack

37 stars 26 forks source link

Interaction with the APT buildpack can cause "libblas.so.3: cannot open shared object file" #18

Closed edmorley closed 3 years ago

edmorley commented 3 years ago

Filing this in case it helps anyone else debugging.

Builds using this buildpack can fail with the following error: OSError: libblas.so.3: cannot open shared object file: No such file or directory

...if all of the following are true:

Example:

$ mkdir testapp-geo-buildpack && cd $_ && git init && h create --stack heroku-18
$ h buildpacks:add https://github.com/heroku/heroku-geo-buildpack
$ h buildpacks:add heroku-community/apt
$ h buildpacks:add heroku/python
$ echo 'gdal-bin' > Aptfile
$ echo 'python-3.8.3' > runtime.txt
$ touch requirements.txt
$ mkdir -p bin
$ cat > bin/post_compile <<EOF
#!/usr/bin/env python
from ctypes import CDLL
from ctypes.util import find_library

lib_path = find_library('gdal')
print(lib_path)
CDLL(lib_path)
EOF
$ git add -A; git commit -m '.' && git push heroku main
...
remote: -----> Running post-compile hook
remote: libgdal.so.20
remote: Traceback (most recent call last):
remote:   File "bin/post_compile", line 9, in <module>
remote:     CDLL(lib_path)
remote:   File "/app/.heroku/python/lib/python3.8/ctypes/__init__.py", line 373, in __init__
remote:     self._handle = _dlopen(self._name, mode)
remote: OSError: libblas.so.3: cannot open shared object file: No such file or directory

If you experience the above error, the way to resolve is to either:

  1. Remove gdal related dependencies from Aptfile (and leave them to the Geo buildpack)
  2. Or, if you really need those dependencies for some reason (even though they duplicate the libraries used in this buildpack), then change the buildpack order, such that the Geo buildpack is after the APT buildpack, so that the GDAL libraries are used from the Geo buildpack and not the broken install from the APT buildpack

The long term solution is for the APT buildpack to fix heroku/heroku-buildpack-apt/issues/64.