This is a bug I cannot reproduce with simple code. I'm working with ubuntu 16.04 and gdal 2.2.3, in python3.

When I try to open a geojson with ogr in my programm:

src_ds = ogr.Open('/data/train/AOI_2_Vegas_Train/geojson/line/line_AOI_2_Vegas_img2389.geojson')

I get an error which is a segfault I guess:

Fatal Python error: PyThreadState_Get: no current thread

Current thread 0x00007f2bb0fcd700 (most recent call first):
  File "/home/myhome/project/env/local/lib/python3.5/site-packages/osgeo/ogr.py", line 7923 in Open

but when I try it in the python console, or in a small script, it works. I extracted the part of my code leading to this bug, but when I execute it separately from the rest of my code it works:

import gdal
import ogr

rgb_fn = '/data/train/AOI_2_Vegas_Train/RGB-PanSharpen/RGB-PanSharpen_AOI_2_Vegas_img2389.tif'
rgb_ds = gdal.Open(rgb_fn, gdal.GA_ReadOnly)
driver = gdal.GetDriverByName('GTiff')

def _get_raster_properties(raster_ds):
     # get reference properties
     x_size = raster_ds.RasterXSize
     y_size = raster_ds.RasterYSize
     geotransform = raster_ds.GetGeoTransform()
     projection = raster_ds.GetProjection()
     return x_size, y_size, geotransform, projection

x_size, y_size, geotransform, projection = _get_raster_properties(rgb_ds)

line_ds = driver.Create('/tmp/line_ds.tif', x_size, y_size, 1, gdal.GDT_Byte)

line_fn = '/data/train/AOI_2_Vegas_Train/geojson/line/line_AOI_2_Vegas_img2389.geojson'
src_ds = ogr.Open(line_fn)  # this is failing in my code, but not here

gdal.RasterizeLayer(line_ds, [1], src_ds.GetLayer(), burn_values=[1])

this script is the equivalent of the code I am runnig in my program, with the same file treated.

Is this a gdal bug?

  • in the first case you use a relative path whereas in the second case you use an absolute path. However it seems that you use different python versions in your command line than in your python script. I would recommend to use a conda environment or at least a virtual environment.
    – RutgerH
    Feb 15, 2018 at 15:58
  • I use the same file with the same path everywhere. the 'my_path' bit was just to give an example of the command used.
    – Borbag
    Feb 15, 2018 at 16:17
  • gdal is only installed in this environment, which I use for both the python command and the script.
    – Borbag
    Feb 15, 2018 at 16:18

1 Answer 1


This error has been raised for me when using gdal.Open() on an invalid file path. I recommend explicitly verifying all of your paths exist before handing them to gdal to make these errors a bit easier to recognize.

from pathlib import Path 
path = Path("my/image/path.tif")
if not path.exists():
    raise FileNotFoundError

or using the os module

import os
path = "my/image/path.tif"
if not os.path.exists(path):
    raise FileNotFoundError

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.