question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error (GDAL) while importing fiona in Python3 (Ubuntu 18.04)

See original GitHub issue

I 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:open
  • Created 3 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
rbuffatcommented, Jul 8, 2020

@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.

0reactions
jdmcbrcommented, Aug 17, 2020

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error when installing GDAL 3.0.4 on Ubuntu 18.04
I'm trying to install GDAL through pip with same version in the system. But I'm getting this error: (app_env) user@server:~$ pip install ...
Read more >
import geopandas successfully, but raise issue with fiona ...
It seemed work at first because I could successfully import geopandas without error, but when I want to run the following code, an...
Read more >
pip install geopandas error | The AI Search Engine You Control
First try to conda install -c conda-forge geopandas . If it doesn't work, do the following steps: Download wheels for your Python version...
Read more >
Fiona - PyPI
Fiona is GDAL's neat and nimble vector API for Python programmers. ... its certificate store location will be passed to GDAL during import...
Read more >
rasterio Documentation - Read the Docs
Todo: error enums, context managers, converting GDAL errors to python ... Using rasterio with fiona, it is simple to open a shapefile, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found