2

I try to loop through a folder containing multiple geodatabases (12). After performing some calculation I try to save the results in a new shapefile located in another folder, but the code generates only three shapefiles. I also get following message during the creation:

[...]
it__
  File "fiona/_shim.pyx", line 73, in fiona._shim.gdal_open_vector
    self.session.start(self, **kwargs)
  File "fiona/ogrext.pyx", line 467, in fiona.ogrext.Session.start
  File "fiona/_shim.pyx", line 73, in fiona._shim.gdal_open_vector
fiona.errors.DriverError: database is locked
  File "fiona/_shim.pyx", line 73, in fiona._shim.gdal_open_vector
  File "fiona/ogrext.pyx", line 467, in fiona.ogrext.Session.start
fiona.errors.DriverError: database is locked
fiona.errors.DriverError: database is locked
  File "fiona/_shim.pyx", line 73, in fiona._shim.gdal_open_vector
fiona.errors.DriverError: database is locked

Here I have some code:

for file in glob.glob('[mypath]\\*[0-9].gpkg' ):

    layer = gpd.read_file(str(file), layer = os.path.splitext(os.path.basename(file))[0])

#[...doing something...]

if __name__ == '__main__':

    layer.to_file(f'[mypath]\\{os.path.splitext(os.path.basename(file))[0]}.shp', driver = "ESRI Shapefile")

Like the message indicates is there some problem with the database connection. Should I close the connection after every run in the loop? And how do I do it?

I'm using Windows 10 and Python 3.7.

  • 1
    Have you tried to open the gpkg connection as read-only? – user30184 Feb 4 at 11:49
  • I add mode='r', but the error still occurs. – DrSnuggles Feb 5 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.