Error in importing Geopandas when deploying on streamlit sharing

Trying to deploy a streamlit app on streamlit sharing. The app works fine both locally and in docker. However, on streamlit sharing it gives me the following error on the log file:

import geopandas as gpd

File "/home/appuser/.conda/lib/python3.7/site-packages/geopandas/__init__.py", line 1, in <module>

from geopandas._config import options  # noqa

File "/home/appuser/.conda/lib/python3.7/site-packages/geopandas/_config.py", line 126, in <module> default_value=_default_use_pygeos(),

File "/home/appuser/.conda/lib/python3.7/site-packages/geopandas/_config.py", line 112, in _default_use_pygeos

import geopandas._compat as compat

File "/home/appuser/.conda/lib/python3.7/site-packages/geopandas/_compat.py", line 10, in <module>

import shapely.geos

File "/home/appuser/.conda/lib/python3.7/site-packages/shapely/geos.py", line 87, in <module>  _lgeos = load_dll('geos_c', fallbacks=alt_paths)

File "/home/appuser/.conda/lib/python3.7/site-packages/shapely/geos.py", line 62, in load_dll libname, fallbacks or []))

OSError: Could not find lib geos_c or load any of its variants ['libgeos_c.so.1', 'libgeos_c.so'].

Should be something related to GEOS dependency with shapely and geopandas. Does anyone know how to solve it?

Hi @giobbu, welcome to the Streamlit community!

To add system-level dependencies, you can create a packages.txt file. In the case of GEOS, try adding libgeos-dev into the packages.txt file, commit it to GitHub and see if that loads your app.

Best,
Randy

1 Like

Thanks for that! However, now it is giving me this :

ERROR 1: PROJ: proj_create_from_database: Open of /home/appuser/.conda/share/proj failed

/home/appuser/.conda/lib/python3.7/site-packages/pyproj/__init__.py:73: UserWarning: Valid PROJ data directory not found. Either set the path using the environmental variable PROJ_LIB or with `pyproj.datadir.set_data_dir`.

  warnings.warn(str(err))

I guess it is still related with geopandas.

Either set the path using the environmental variable PROJ_LIB or with pyproj.datadir.set_data_dir

Hi @giobbu,

I resolved the error by setting the path using the environmental variable PROJ_LIB. Add the following lines to the top of run_.py before you import other modules:

import conda
import os

conda_file_dir = conda.__file__
conda_dir = conda_file_dir.split('lib')[0]
proj_lib = os.path.join(os.path.join(conda_dir, 'share'), 'proj')
os.environ["PROJ_LIB"] = proj_lib

Once you make the above change and reboot, your app should work! :balloon:

Happy Streamlit’ing!
Snehan

Source: KeyError 'PROJ_LIB' · Issue #30 · conda-forge/basemap-feedstock · GitHub

2 Likes