Skip to content

pyogrio.errors.DataSourceError: No driver registered #448

@weiji14

Description

@weiji14

We've been hitting into an issue on pyogrio not being able to detect GDAL drivers in our Sphinx docs build CI since two weeks ago (GenericMappingTools/pygmt#3301), with errors like:

  • pyogrio.errors.DataSourceError: No driver registered.
  • pyogrio.errors.DataSourceError: Could not obtain driver: OGR_GMT (check that it was installed correctly into GDAL)

We're using geopandas=1.0.1 (pyhd8ed1ab_0) and pyogrio=0.9.0 (py312h8ad7a51_0) installed from conda-forge, which includes the OGR_GMT driver (installed in GDAL=3.9.0 (py312h86af8fa_5)). This issue has been very hard to reproduce, because things work when we test things directly, but fail when running the scripts with sphinx-build. E.g. this code example:

import geopandas as gpd
import pyogrio

pyogrio.list_drivers()
gdf = gpd.read_file(
    "https://www2.census.gov/geo/tiger/TIGER2015/PRISECROADS/tl_2015_15_prisecroads.zip",
    engine="pyogrio",
)

would consistently produce a pyogrio.errors.DataSourceError: No driver registered error when ran as part of sphinx-build:

{}
ERROR 4: No driver registered./lines... [ 85%] roads.py

Traceback (most recent call last):
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/site-packages/sphinx_gallery/gen_rst.py", line 975, in execute_code_block
    is_last_expr, mem_max = _exec_and_get_memory(
                            ^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/site-packages/sphinx_gallery/gen_rst.py", line 807, in _exec_and_get_memory
    mem_body, _ = call_memory(
                  ^^^^^^^^^^^^
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/site-packages/sphinx_gallery/gen_rst.py", line 1594, in _sg_call_memory_noop
    return 0.0, func()
                ^^^^^^
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/site-packages/sphinx_gallery/gen_rst.py", line 728, in __call__
    exec(self.code, self.fake_main.__dict__)
  File "/home/user/Documents/github/pygmt/examples/gallery/lines/roads.py", line 22, in <module>
    gdf = gpd.read_file(
          ^^^^^^^^^^^^^^
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/site-packages/geopandas/io/file.py", line 294, in _read_file
    return _read_file_pyogrio(
           ^^^^^^^^^^^^^^^^^^^
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/site-packages/geopandas/io/file.py", line 547, in _read_file_pyogrio
    return pyogrio.read_dataframe(path_or_bytes, bbox=bbox, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/site-packages/pyogrio/geopandas.py", line 261, in read_dataframe
    result = read_func(
             ^^^^^^^^^^
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/site-packages/pyogrio/raw.py", line 196, in read
    return ogr_read(
           ^^^^^^^^^
  File "pyogrio/_io.pyx", line 1239, in pyogrio._io.ogr_read
  File "pyogrio/_io.pyx", line 219, in pyogrio._io.ogr_open
pyogrio.errors.DataSourceError: No driver registered.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/site-packages/sphinx/cmd/build.py", line 332, in build_main
    app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/site-packages/sphinx/application.py", line 268, in __init__
    self._init_builder()
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/site-packages/sphinx/application.py", line 339, in _init_builder
    self.events.emit('builder-inited')
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/site-packages/sphinx/events.py", line 97, in emit
    results.append(listener.handler(self.app, *args))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/site-packages/sphinx_gallery/gen_gallery.py", line 616, in generate_gallery_rst
    ) = generate_dir_rst(src_dir, target_dir, gallery_conf, seen_backrefs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/site-packages/sphinx_gallery/gen_rst.py", line 539, in generate_dir_rst
    intro, title, (t, mem) = generate_file_rst(
                             ^^^^^^^^^^^^^^^^^^
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/site-packages/sphinx_gallery/gen_rst.py", line 1211, in generate_file_rst
    output_blocks, time_elapsed = execute_script(
                                  ^^^^^^^^^^^^^^^
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/site-packages/sphinx_gallery/gen_rst.py", line 1116, in execute_script
    execute_code_block(
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/site-packages/sphinx_gallery/gen_rst.py", line 988, in execute_code_block
    except_rst = handle_exception(
                 ^^^^^^^^^^^^^^^^^
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/site-packages/sphinx_gallery/gen_rst.py", line 664, in handle_exception
    func(  # needs leading newline to get away from iterator
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/site-packages/sphinx/util/logging.py", line 184, in warning
    return super().warning(
           ^^^^^^^^^^^^^^^^
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/logging/__init__.py", line 1930, in warning
    self.log(WARNING, msg, *args, **kwargs)
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/site-packages/sphinx/util/logging.py", line 131, in log
    super().log(level, msg, *args, **kwargs)
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/logging/__init__.py", line 1962, in log
    self.logger.log(level, msg, *args, **kwargs)
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/logging/__init__.py", line 1609, in log
    self._log(level, msg, args, **kwargs)
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/logging/__init__.py", line 1684, in _log
    self.handle(record)
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/logging/__init__.py", line 1700, in handle
    self.callHandlers(record)
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/logging/__init__.py", line 1762, in callHandlers
    hdlr.handle(record)
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/logging/__init__.py", line 1022, in handle
    rv = self.filter(record)
         ^^^^^^^^^^^^^^^^^^^
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/logging/__init__.py", line 858, in filter
    result = f.filter(record)
             ^^^^^^^^^^^^^^^^
  File "/home/user/mambaforge/envs/pygmt/lib/python3.12/site-packages/sphinx/util/logging.py", line 478, in filter
    raise exc
sphinx.errors.SphinxWarning: 
../examples/gallery/lines/roads.py unexpectedly failed to execute correctly:

or produce the expected output when ran directly in a Python script or Jupyter notebook:

Details
{'FITS': 'rw',
 'PCIDSK': 'rw',
 'netCDF': 'rw',
 'PDS4': 'rw',
 'VICAR': 'rw',
 'JP2OpenJPEG': 'r',
 'PDF': 'rw',
 'MBTiles': 'rw',
 'TileDB': 'rw',
 'BAG': 'rw',
 'EEDA': 'r',
 'OGCAPI': 'r',
 'ESRI Shapefile': 'rw',
 'MapInfo File': 'rw',
 'UK .NTF': 'r',
 'LVBAG': 'r',
 'OGR_SDTS': 'r',
 'S57': 'rw',
 'DGN': 'rw',
 'OGR_VRT': 'r',
 'Memory': 'rw',
 'CSV': 'rw',
 'NAS': 'r',
 'GML': 'rw',
 'GPX': 'rw',
 'LIBKML': 'rw',
 'KML': 'rw',
 'GeoJSON': 'rw',
 'GeoJSONSeq': 'rw',
 'ESRIJSON': 'r',
 'TopoJSON': 'r',
 'Interlis 1': 'rw',
 'Interlis 2': 'rw',
 'OGR_GMT': 'rw',
 'GPKG': 'rw',
 'SQLite': 'rw',
 'WAsP': 'rw',
 'PostgreSQL': 'rw',
 'OpenFileGDB': 'rw',
 'DXF': 'rw',
 'CAD': 'r',
 'FlatGeobuf': 'rw',
 'Geoconcept': 'rw',
 'GeoRSS': 'rw',
 'VFK': 'r',
 'PGDUMP': 'rw',
 'OSM': 'r',
 'GPSBabel': 'rw',
 'OGR_PDS': 'r',
 'WFS': 'r',
 'OAPIF': 'r',
 'EDIGEO': 'r',
 'SVG': 'r',
 'Idrisi': 'r',
 'XLS': 'r',
 'ODS': 'rw',
 'XLSX': 'rw',
 'Elasticsearch': 'rw',
 'Carto': 'rw',
 'AmigoCloud': 'rw',
 'SXF': 'r',
 'Selafin': 'rw',
 'JML': 'rw',
 'PLSCENES': 'r',
 'CSW': 'r',
 'VDV': 'rw',
 'GMLAS': 'r',
 'MVT': 'rw',
 'NGW': 'rw',
 'MapML': 'rw',
 'GTFS': 'r',
 'PMTiles': 'rw',
 'JSONFG': 'rw',
 'MiraMonVector': 'rw',
 'TIGER': 'r',
 'AVCBin': 'r',
 'AVCE00': 'r',
 'HTTP': 'r'}
        LINEARID      FULLNAME RTTYP  MTFCC  \
0  1104258643968  Puainako Exd     M  S1200   
1  1103933153286   Puanako Exd     M  S1200   
2  1103890709860  Puainako Exd     M  S1200   
3  1104486222576     Keaau Byp     M  S1200   
4  1104486197669     Keaau Byp     M  S1200   

                                            geometry  
0  LINESTRING (-155.11039 19.69256, -155.1107 19....  
1  LINESTRING (-155.14804 19.68121, -155.14938 19...  
2  LINESTRING (-155.1566 19.68084, -155.15641 19....  
3  LINESTRING (-155.0313 19.62267, -155.03204 19....  
4  LINESTRING (-155.02989 19.61407, -155.02981 19...  

My guess is that the GDAL drivers are not being registered properly somehow. This was supposedly fixed in #145 (see also #144), but there might be certain cases where the loading doesn't happen correctly? We have a workaround right now that forces the driver load like so:

import pyogrio

pyogrio.core._register_drivers()

but given that _register_drivers is a private method, we would prefer not to rely on it. We're opening this issue to try to figure out where the GDAL driver loading logic might be failing even after #145. Unsure if putting GDALAllRegister() back in _io.pyx and/or _ogr.pyx would help, or if there is another solution we can try.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions