Error (GDAL) while importing fiona in Python3 (Ubuntu 18.04)
See original GitHub issueI met the following error while importing Fiona in Python3 on Ubuntu 18.04 after having freshly upgraded GDAL to its version 3.1.0:
>>> import fiona
ERROR 4: Unable to open EPSG support file gcs.csv.
Try setting the GDAL_DATA environment variable to point
to the directory containing EPSG csv files.
Further details here:
https://github.com/OSGeo/gdal/issues/2500
https://github.com/geopandas/geopandas/issues/1408
It seems that both fiona
and rasterio
keep installing this gcs.csv
file which is no more needed by GDAL apparently in /usr/local/lib/python3.6/dist-packages/fiona/gdal_data/
and /usr/local/lib/python3.6/dist-packages/rasterio/gdal_data/
, both installed with sudo -H pip3 install -U <package-name>
.
>>> import fiona
ERROR 4: Unable to open EPSG support file gcs.csv.
Try setting the GDAL_DATA environment variable to point
to the directory containing EPSG csv files.
>>>
The same error is raised when calling the system tool fio
in a bash terminal:
$ fio --help
ERROR 4: Unable to open EPSG support file gcs.csv.
Try setting the GDAL_DATA environment variable to point
to the directory containing EPSG csv files.
Usage: fio [OPTIONS] COMMAND [ARGS]...
(...)
But If I do import rasterio
first, fiona
stops complaining:
>>> import rasterio
>>> import fiona
>>>
Environment
OS: Ubuntu 18.04.
Python3: Python 3.6.9 (default, Apr 18 2020, 01:56:04)
gdalinfo --version: GDAL 3.1.0, released 2020/05/03
fiona:
>>> import fiona
>>> fiona.__version__
'1.8.13.post1'
>>> fiona.__file__
'/usr/local/lib/python3.6/dist-packages/fiona/__init__.py'
EDIT
I first installed gdal from apt
long time ago, prior to every other things, which for Ubuntu 18.04 is:
$ apt-cache policy gdal-bin
gdal-bin:
Installed: 2.4.0+10-0bionic1
Candidate: 2.4.0+10-0bionic1
Version table:
*** 2.4.0+10-0bionic1 100
100 /var/lib/dpkg/status
2.2.3+dfsg-2 500
500 http://ch.archive.ubuntu.com/ubuntu bionic/universe amd64 Packages
I installed Fiona (and almost all my favorite geo spatial libraries) with pip
(20.1), which is currently;
Fiona-1.8.13.post1-cp36-cp36m-manylinux1_x86_64.whl (14.7 MB)
and raterio:
rasterio-1.1.4-cp36-cp36m-manylinux1_x86_64.whl (18.2 MB)
I usually do it like:
sudo -H pip3 install -U <package-name>
(-U
for upgading to its latest available version).
That’s why the packages installed this way go to /usr/local
instead of /usr
directly. Which is fine.
Then, yesterday, I faced some issues while inserting data in a PostgreSQL v.12 database using ogr2ogr
. I figured out it was fixed in a recent commit so I decided to upgrade GDAL itself, from source, because the version from apt
was too old. Therefore, I downloaded version 3.1.0
from here; https://github.com/OSGeo/gdal/releases/tag/v3.1.0 , compiled it, and installed it using checkinstall
tool.
Now gdal version is:
$ gdalinfo --version
GDAL 3.1.0, released 2020/05/03
Then I upgade the python gdal
package also using pip
. This was the shipped wheel:
GDAL-3.1.0-cp36-cp36m-linux_x86_64.whl
=>
>>> from osgeo import gdal
>>> gdal.__version__
'3.1.0'
>>> gdal.__file__
'/usr/local/lib/python3.6/dist-packages/osgeo/gdal.py'
>>>
I did not uninstall gdal 2.4 (the apt
version) because many (many!) other softwares I also installed with apt
, such as QGIS relies on it and would be dropped as well by apt!
After what I figured out the error message while loading geopandas
, which brings me here aswell because loading fiona
itself causes the same error. But strangely, if I load rasterio
prior to fiona
everything goes well. This is obscure to me.
Here is the last piece of information which was asked for:
>>> from fiona._env import get_gdal_release_name
>>> print(get_gdal_release_name())
2.4.4
>>>
These are also the 3 places I can find the file causing troubles:
$ find /usr -iname gcs.csv
/usr/share/gdal/2.4/gcs.csv
/usr/local/lib/python3.6/dist-packages/rasterio/gdal_data/gcs.csv
/usr/local/lib/python3.6/dist-packages/fiona/gdal_data/gcs.csv
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (6 by maintainers)
Top GitHub Comments
@demiurg @rdmurphy The fix is already merged in maint-1.8 branch but not yet released. Until a new release is out, you could either manually apply the fix from https://github.com/Toblerity/Fiona/issues/897#issuecomment-626223187 or use the maint-1.8 branch.
Thanks @swiss-knight and @rbuffat. I did a fresh GDAL 3.1.2 install this weekend and started hitting this, and was confused given I knew the gcs.csv was no longer present in GDAL as of 3.0. Installing from maint-1.8 solved it!