Fiona: Ubuntu12 Python2.7 Anaconda2-4.1 Fiona1.7 listlayers() ValueError: OGR/GPX driver has not been built with read support

Created on 14 Jul 2016  路  17Comments  路  Source: Toblerity/Fiona

When I'm trying to load GPX-file using python module Fiona appears error
ValueError: OGR/GPX driver has not been built with read support. Expat library required

in python

>>> fname='/home/o/jp/run.gpx'
>>> import fiona
>>> fiona.listlayers(fname)
 ERROR 6: OGR/GPX driver has not been built with read support. Expat library required
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "/media/disk2/ana2/lib/python2.7/site-packages/fiona/__init__.py", line 239, in listlayers
     return _listlayers(vsi_path(path, vsi, archive))
   File "fiona/ogrext.pyx", line 1289, in fiona.ogrext._listlayers (fiona/ogrext2.c:20494)
   File "fiona/_err.pyx", line 67, in fiona._err.GDALErrCtxManager.__exit__ (fiona/_err.c:1009)
 ValueError: OGR/GPX driver has not been built with read support. Expat library required

see using fiona for loading GPX-files
https://ocefpaf.github.io/python4oceanographers/blog/2015/08/03/fiona_gpx/

Fiona uses GDAL
https://pypi.python.org/pypi/GDAL/

I have build and install it from sourses according
https://trac.osgeo.org/gdal/wiki/BuildingOnUnix
./configure --prefix=/media/disk2/gdal/

>>> fiona.__version__
'1.7.0.post2'

gdal-config --version =2.1.0

How can I fix it?

bug upstream wontfix

All 17 comments

This is not an issue of Fiona. The gdal you have installed has the support for the expat library not compiled in.

Maybe the gdal version of the ubuntugis ppa has expat support: https://launchpad.net/~ubuntugis
Otherwise you can compile gdal with expat enabled on your own from the source code: http://trac.osgeo.org/gdal/wiki/BuildingOnUnix

Edit: I just saw that you compile from source. Do you have the libexpat-dev package installed. When you execute ./configure to install gdal you should see if the support for expat is enabled or not.

How can I enable "expat" while compiling GDAL?
I search in
./configure --help
there is no switches to turn it on...

I suspect you are missing the libexpat-dev package. If you have installed the libexpat manually you need to ensure that it is in the LD_LIBRARY_PATH.

I did not install libexpat-dev manually - it is a part of Ubuntu12, I think
sudo apt-get install libexpat-dev
Transfers libexpat-dev in libexpat1-dev
Allready installed newest version.
ubuntugis stable has gdal 1.10 and 1.11
Is fiona support GDAL version 2.1 ?
How can I remove GDAL 2.1 and install gdal 1.10 ?

Result of ./configure

checking for XML_ParserCreate in -lexpat... yes
checking for Expat XML Parser headers in /usr/include... found
checking for Expat XML Parser... yes
checking if Expat XML Parser version is >= 1.95.0... yes
Expat support:             yes

Can you check if:

  1. you can open the file with gdalinfo of your gdal installation. (check gdalinfo --version)
  2. You installed fiona for the gdal version you have compiled:
>>> import fiona
>>> fiona.__gdal_version__
'1.11.3'

GDAL 2.1 , Fiona 1.7 - are they incompatible?

gdalinfo --version
GDAL 2.1.0, released 2016/04/25
>>> fiona.__version__
'1.7.0.post2'
>>> fiona.gdal_version
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'gdal_version'

Regarding Gdal 2.1, I do not know of any issues:

fiona.__gdal_version__
not
fiona.gdal_version

>>> fiona.__gdal_version__
u'2.1.0'
>>> 

What is the output of ogr2ogr --formats?

"OGR/GPX driver has not been built with read support. Expat library required" is to my knowledge an error message from gdal not from fiona. As fiona points to the correct gdal installation the problem should be with your gdal installation.

As fiona points to the correct gdal installation the problem should be with your gdal installation.

May I ask you for advice - where can I make a question about solving this problem?

o@o-VirtualBox:~$ ogr2ogr --formats
Supported Formats:
  PCIDSK -raster,vector- (rw+v): PCIDSK Database File
  PDF -raster,vector- (w+): Geospatial PDF
  ESRI Shapefile -vector- (rw+v): ESRI Shapefile
  MapInfo File -vector- (rw+v): MapInfo File
  UK .NTF -vector- (ro): UK .NTF
  OGR_SDTS -vector- (ro): SDTS
  S57 -vector- (rw+v): IHO S-57 (ENC)
  DGN -vector- (rw+): Microstation DGN
  OGR_VRT -vector- (rov): VRT - Virtual Datasource
  REC -vector- (ro): EPIInfo .REC 
  Memory -vector- (rw+): Memory
  BNA -vector- (rw+v): Atlas BNA
  CSV -vector- (rw+v): Comma Separated Value (.csv)
  GML -vector- (rw+v): Geography Markup Language (GML)
  GPX -vector- (rw+v): GPX
  KML -vector- (rw+v): Keyhole Markup Language (KML)
  GeoJSON -vector- (rw+v): GeoJSON
  OGR_GMT -vector- (rw+): GMT ASCII Vectors (.gmt)
  WAsP -vector- (rw+v): WAsP .map format
  OpenFileGDB -vector- (rov): ESRI FileGDB
  XPlane -vector- (rov): X-Plane/Flightgear aeronautical data
  DXF -vector- (rw+v): AutoCAD DXF
  Geoconcept -vector- (rw+): Geoconcept
  GeoRSS -vector- (rw+v): GeoRSS
  GPSTrackMaker -vector- (rw+v): GPSTrackMaker
  PGDUMP -vector- (w+v): PostgreSQL SQL dump
  GPSBabel -vector- (rw+): GPSBabel
  SUA -vector- (rov): Tim Newport-Peace's Special Use Airspace Format
  OpenAir -vector- (rov): OpenAir
  OGR_PDS -vector- (rov): Planetary Data Systems TABLE
  HTF -vector- (rov): Hydrographic Transfer Vector
  AeronavFAA -vector- (rov): Aeronav FAA
  EDIGEO -vector- (rov): French EDIGEO exchange format
  SVG -vector- (rov): Scalable Vector Graphics
  Idrisi -vector- (rov): Idrisi Vector (.vct)
  ARCGEN -vector- (rov): Arc/Info Generate
  SEGUKOOA -vector- (rov): SEG-P1 / UKOOA P1/90
  SEGY -vector- (rov): SEG-Y
  SXF -vector- (ro): Storage and eXchange Format
  Selafin -vector- (rw+v): Selafin
  JML -vector- (rw+v): OpenJUMP JML
  VDV -vector- (rw+v): VDV-451/VDV-452/INTREST Data Format
  TIGER -vector- (rw+v): U.S. Census TIGER/Line
  AVCBin -vector- (ro): Arc/Info Binary Coverage
  AVCE00 -vector- (ro): Arc/Info E00 (ASCII) Coverage
o@o-VirtualBox:~$ 

gdal installation is ok,
Expat support: yes

from osgeo import gdal
gdal.__version__
'2.1.0'

How can I check gdal installation?
Error is apearing when run fiona function fiona.listlayers('/home/o/jp/run.gpx')

File "fiona/_err.pyx", line 67, in fiona._err.GDALErrCtxManager.__exit__ (fiona/_err.c:1009)
ValueError: OGR/GPX driver has not been built with read support. Expat library required

So maybe problem with fiona.

May I ask you for advice - where can I make a question about solving this problem?
@rbuffat has been asking you questions in order to make sure that the problem isn't with your installation.

If this can be reproduced on another machine, someone could figure out if it a bug in GDAL, Fiona, or the installation itself. A small upload of a GPX file would be helpful. (I probably haven't used GPX format in 3 or more years.)

Another installation test, does this print some info about successfully opening the GPX file or give an Expat error?

$  ogrinfo run.gpx

Thank you for your help. Found a problem at last.
Solution is
chmod 777 run.gpx
Sorry. Case closed.

A small upload of a GPX file would be helpful
Sure
run.zip

o@o-VirtualBox:~$ cd jp
o@o-VirtualBox:~/jp$ ls -l
-rwxrwx--- 1 o o 202163 褎械胁褉. 25 16:29 run.gpx
o@o-VirtualBox:~/jp$ chmod 777 run.gpx
o@o-VirtualBox:~/jp$ ls -l
-rwxrwxrwx 1 o o 202163 褎械胁褉. 25 16:29 run.gpx
o@o-VirtualBox:~/jp$ ogrinfo run.gpx
Had to open data source read-only.
INFO: Open of `run.gpx'
      using driver `GPX' successful.
1: waypoints (Point)
2: routes (Line String)
3: tracks (Multi Line String)
4: route_points (Point)
5: track_points (Point)
o@o-VirtualBox:~/jp$ python
Python 2.7.11 |Anaconda 4.1.0 (32-bit)| (default, Jun 15 2016, 15:21:34) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import fiona
>>> fiona.listlayers('/home/o/jp/run.gpx')
[u'waypoints', u'routes', u'tracks', u'route_points', u'track_points']
>>> fname='/home/o/jp/run.gpx'
>>> layer = fiona.open(fname, layer='tracks')
>>> layer
<open Collection '/home/o/jp/run.gpx:tracks', mode 'r' at 0xb5e1766cL>
>>> layer.crs, layer.bounds
({'init': u'epsg:4326'}, (29.5603523, 46.7771, 29.6675129, 46.84029))
>>> len(list(layer.items()))
1
>>> geom = layer[0]
>>> type(geom)
<type 'dict'>
>>> geom.keys()
['geometry', 'type', 'id', 'properties']
>>> geom['type'], geom['id'], geom['properties']
('Feature', '0', OrderedDict([(u'name', u'\u041d\u043e\u0432\u043e\u0433\u043e\u0434\u043d\u044f\u044f \u043a\u0430\u043d\u0442\u0440\u0438\u0439\u043d\u0430\u044f on GPSies.com'), (u'cmt', None), (u'desc', None), (u'src', u'http://www.endomondo.com/'), (u'link1_href', u'https://www.endomondo.com/workouts/280654749/10567105'), (u'link1_text', u'\u041d\u043e\u0432\u043e\u0433\u043e\u0434\u043d\u044f\u044f \u043a\u0430\u043d\u0442\u0440\u0438\u0439\u043d\u0430\u044f on GPSies.com'), (u'link1_type', None), (u'link2_href', None), (u'link2_text', None), (u'link2_type', None), (u'number', None), (u'type', u'CYCLING_SPORT')]))
>>> 

Fiona should report a more helpful file permission error message, not one that a required library wasn't compiled.

@micahcochran That's probably harder than it sounds. Fiona is just forwarding the error message from GDAL. The issue should probably be addressed in GDAL rather than Fiona.

@snorfalorpagus right, the problem is that the GPX driver doesn't open the GPX file (which would reveal the lack of permission) before https://github.com/OSGeo/gdal/blob/trunk/gdal/ogr/ogrsf_frmts/gpx/ogrgpxdatasource.cpp#L291.

This is a GDAL bug, in the GPX driver specifically. I'm sorry it tripped you up, @filin2009. Would you be willing to create a bug report about this in the GDAL tracker?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sgillies picture sgillies  路  4Comments

mdklatt picture mdklatt  路  6Comments

epifanio picture epifanio  路  4Comments

sgillies picture sgillies  路  4Comments

nyotta picture nyotta  路  7Comments