GeoPandas Not Reading Shapefile: Common Causes and Fixes
On this page
Problem statement
geopandas.read_file() either refuses the shapefile or, worse, opens it and returns something incomplete. The symptoms:
- GeoPandas raises an error instead of loading the data
- the shapefile opens, but attributes, geometries or the CRS are missing
- the file path looks correct, but Python says the file does not exist
- the same data opens in one tool but not in another
Behind them sit six causes:
- a bad file path
- missing shapefile components like
.shx,.dbf,.prjor.cpg - a ZIP archive that holds more than one layer
- a truncated or zero-byte file from an interrupted download or copy
- text encoding
- an environment without a working read engine
Every failure on this page was reproduced with GeoPandas 1.1, pyogrio 0.13 and GDAL 3.12 on two real downloads: Natural Earth's 1:50 million populated places (1,251 points, a classic single-layer shapefile) and Geofabrik's OpenStreetMap shapefile extract for Rutland, a ZIP of 18 layers. Several of them do not raise an error at all.
Quick answer
Most shapefile read problems in GeoPandas are found by checking these items in order:
- Print the resolved path and confirm it exists.
- Confirm the
.shxand.dbfare next to the.shp, with the same base name. - For a ZIP, list its layers with
pyogrio.list_layers()and passlayer=. - After reading, check the row count,
geometry.isna().sum(), the columns andcrsβ the silent failures only show up there. - If text looks garbled, pass
encoding=. - If the message is unhelpful, try the other engine: pyogrio names the missing
.shx, Fiona only says it failed to open.
import geopandas as gpd
places = gpd.read_file("data/places/ne_50m_populated_places.shp")
print(len(places), "rows,", places.geometry.isna().sum(), "without geometry,",
len(places.columns) - 1, "attribute columns, CRS", places.crs)
1251 rows, 0 without geometry, 137 attribute columns, CRS EPSG:4326
That one line of checks is the baseline every broken copy below is compared against.
Diagnosis at a glance
The path to pass, required parts, verified locations
1. What path to pass
The usual advice is to pass the .shp file. That is the clearest choice, but GDAL is more forgiving than the advice suggests:
base = "data/places/ne_50m_populated_places"
for path in [base + ".shp", base + ".dbf", base + ".shx", "data/places"]:
layer = gpd.read_file(path)
print(f"{path:44} {len(layer)} rows, geometry: {layer.geometry.notna().all()}")
data/places/ne_50m_populated_places.shp 1251 rows, geometry: True
data/places/ne_50m_populated_places.dbf 1251 rows, geometry: True
data/places/ne_50m_populated_places.shx 1251 rows, geometry: True
data/places 1251 rows, geometry: True
The .dbf, the .shx and the folder all open the same layer. A folder is read as a data source of every shapefile in it, so it works here only because the folder holds one; with several, you get the first and a warning, exactly as with the ZIP in step 4.
2. Check that the required shapefile components are present
A shapefile is several files with one base name:
.shpβ geometry.shxβ the index into the.shp.dbfβ the attribute table.prjβ the coordinate reference system (optional, but see below).cpgβ the text encoding of the.dbf(optional, but see step 5)
What happens when one is missing is not what most people expect. Removing each in turn from a copy of the populated places:
import os
import shutil
def without(ext):
folder = f"broken/no_{ext}"
shutil.rmtree(folder, ignore_errors=True)
shutil.copytree("data/places", folder)
os.remove(f"{folder}/ne_50m_populated_places.{ext}")
return f"{folder}/ne_50m_populated_places.shp"
for ext in ["shx", "dbf", "prj"]:
try:
layer = gpd.read_file(without(ext))
print(f".{ext} missing: {len(layer)} rows, {len(layer.columns) - 1} attribute columns, CRS {layer.crs}")
except Exception as err:
print(f".{ext} missing: {type(err).__name__}: {err}")
.shx missing: DataSourceError: Unable to open broken/no_shx/ne_50m_populated_places.shx or broken/no_shx/ne_50m_populated_places.SHX. Set SHAPE_RESTORE_SHX config option to YES to restore or create it.
.dbf missing: 1251 rows, 0 attribute columns, CRS EPSG:4326
.prj missing: 1251 rows, 137 attribute columns, CRS None
Only the missing .shx stops the read, and its message says how to recover. A missing .dbf returns every geometry and no attributes; a missing .prj returns everything but the CRS. Neither raises or warns. The .shx can be rebuilt from the .shp, because it is only an index:
import pyogrio
pyogrio.set_gdal_config_options({"SHAPE_RESTORE_SHX": True})
print(len(gpd.read_file("broken/no_shx/ne_50m_populated_places.shp")), "rows;",
"rebuilt .shx:", os.path.exists("broken/no_shx/ne_50m_populated_places.shx"))
pyogrio.set_gdal_config_options({"SHAPE_RESTORE_SHX": None})
1251 rows; rebuilt .shx: True
GDAL writes the new .shx next to the .shp, so the folder must be writable. A missing .dbf or .prj cannot be rebuilt: get the full set again.
3. Verify the file path is correct
Many shapefile read problems are simple path issues: a wrong working directory, a typo, a renamed file, a Windows backslash sequence, or a network drive that is not mounted. The message for a path that does not exist is plain:
from pathlib import Path
path = Path("data/places/ne_50m_populated_place.shp") # one letter short
print("Reading:", path.resolve().relative_to(Path.cwd()), "| exists:", path.exists())
try:
gpd.read_file(path)
except Exception as err:
print(type(err).__name__ + ":", err)
Reading: data/places/ne_50m_populated_place.shp | exists: False
DataSourceError: data/places/ne_50m_populated_place.shp: No such file or directory
Printing path.resolve() shows the directory Python is actually looking in, which is usually where the mistake is. On Windows, write paths as raw strings (r"C:\gis\data\parcels.shp") or with forward slashes, so that \t or \n in a folder name is not read as a tab or a newline.
4. Reading from a ZIP: pick the layer
GeoPandas reads a zipped shapefile directly; there is no need to extract it. The trap is a ZIP with more than one layer, which is how most portals ship data. Geofabrik's Rutland extract holds 18:
import warnings
print(len(pyogrio.list_layers("data/rutland.zip")), "layers, e.g.", pyogrio.list_layers("data/rutland.zip")[:3, 0].tolist())
with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter("always")
first = gpd.read_file("data/rutland.zip")
print(len(first), "rows from the default layer;", str(caught[0].message)[:70], "...")
places = gpd.read_file("data/rutland.zip", layer="gis_osm_places_free_1")
also = gpd.read_file("zip://data/rutland.zip!gis_osm_places_free_1.shp")
print(len(places), "places with layer=;", len(also), "with a zip://...!member path")
18 layers, e.g. ['gis_osm_buildings_a_free_1', 'gis_osm_landuse_a_free_1', 'gis_osm_natural_a_free_1']
5513 rows from the default layer; More than one layer found in 'rutland.zip': 'gis_osm_buildings_a_free_ ...
300 places with layer=; 300 with a zip://...!member path
Without layer=, you get the first layer in the archive β here 5,513 buildings β and a warning that is easy to miss in a notebook. Name the layer, or point at the member with zip://archive.zip!member.shp.
5. Look for encoding problems
The .cpg file names the encoding of the .dbf. When it is missing, GDAL assumes ISO-8859-1 (Latin-1). Natural Earth's .dbf is UTF-8, and 80 of its 1,251 place names contain non-ASCII characters:
utf8 = gpd.read_file(without("cpg"))
correct = gpd.read_file("data/places/ne_50m_populated_places.shp")
wrong = utf8["NAME"] != correct["NAME"]
print(wrong.sum(), "names changed, e.g.", utf8.loc[wrong, "NAME"].head(3).tolist())
print("fixed:", gpd.read_file(without("cpg"), encoding="utf-8").loc[wrong, "NAME"].head(3).tolist())
80 names changed, e.g. ['BesanΓΒ§on', 'OrlΓΒ©ans', 'AmundsenΓ’\x80\x93Scott South Pole Station']
fixed: ['BesanΓ§on', 'OrlΓ©ans', 'AmundsenβScott South Pole Station']
No error and no warning: every accented name is silently garbled, and a later join on names fails. Pass encoding= when the .cpg is missing.
The opposite case β a legacy Windows-1252 file with no .cpg β is subtler, because Latin-1 and Windows-1252 agree on most accented letters. Writing the same places as Windows-1252 and removing the .cpg:
correct[["NAME", "geometry"]].to_file("broken/places_1252.shp", encoding="cp1252")
os.remove("broken/places_1252.cpg")
legacy = gpd.read_file("broken/places_1252.shp")
print(legacy.loc[wrong, "NAME"].head(3).tolist())
print(gpd.read_file("broken/places_1252.shp", encoding="cp1252").loc[wrong, "NAME"].head(3).tolist())
['BesanΓ§on', 'OrlΓ©ans', 'Amundsen\x96Scott South Pole Station']
['BesanΓ§on', 'OrlΓ©ans', 'AmundsenβScott South Pole Station']
BesanΓ§on survives, but the en dash in AmundsenβScott South Pole Station, which Windows-1252 stores as byte 0x96, comes back as an invisible control character. (Writing the file also warned that some characters could not be converted at all: Windows-1252 has no Ε for TΓΌrkmenbaΕy.)
6. Check for truncated or zero-byte files
An interrupted download or copy leaves a file that is shorter than it should be. What GeoPandas does with it depends on which file was cut:
def cut(ext, keep):
folder = f"broken/cut_{ext}_{keep}"
shutil.rmtree(folder, ignore_errors=True)
shutil.copytree("data/places", folder)
target = f"{folder}/ne_50m_populated_places.{ext}"
with open(target, "r+b") as f:
f.truncate(int(os.path.getsize(target) * keep))
return f"{folder}/ne_50m_populated_places.shp"
for ext, keep in [("shp", 0.5), ("shp", 0), ("dbf", 0)]:
try:
layer = gpd.read_file(cut(ext, keep))
print(f".{ext} cut to {keep:.0%}: {len(layer)} rows, {layer.geometry.isna().sum()} null geometries, "
f"{len(layer.columns) - 1} attribute columns")
except Exception as err:
print(f".{ext} cut to {keep:.0%}: {type(err).__name__}: {str(err)[:80]}")
.shp cut to 50%: 1251 rows, 628 null geometries, 137 attribute columns
.shp cut to 0%: DataSourceError: 'broken/cut_shp_0/ne_50m_populated_places.shp' not recognized as being in a supp
.dbf cut to 0%: 1251 rows, 0 null geometries, 0 attribute columns
The half-length .shp is the dangerous one: every row loads, and 628 of them β the ones whose shapes were in the missing half β have no geometry, without an error or a warning. A zero-byte .shp fails to open; a zero-byte .dbf behaves like a missing one. Checking sizes is cheap:
for path in sorted(Path("broken/cut_shp_0.5").glob("*")):
print(f"{path.name:40} {path.stat().st_size:>9,} bytes")
ne_50m_populated_places.README.html 39,371 bytes
ne_50m_populated_places.VERSION.txt 7 bytes
ne_50m_populated_places.cpg 5 bytes
ne_50m_populated_places.dbf 8,229,743 bytes
ne_50m_populated_places.prj 145 bytes
ne_50m_populated_places.shp 17,564 bytes
ne_50m_populated_places.shx 10,108 bytes
A size alone does not prove a file is complete, but a zero, or a .shp that is suspiciously smaller than the source's, is worth a re-download before anything else.
7. When the message is unhelpful, try the other engine
read_file() uses pyogrio by default; Fiona is the older engine and is optional. Both use GDAL, so they succeed and fail on the same files β but they do not report failures equally well:
no_shx = without("shx") # a fresh copy: step 2 rebuilt the last one
for engine in ["pyogrio", "fiona"]:
try:
gpd.read_file(no_shx, engine=engine)
except Exception as err:
print(f"{engine:8} {type(err).__name__}: {str(err)[:110]}")
pyogrio DataSourceError: Unable to open broken/no_shx/ne_50m_populated_places.shx or broken/no_shx/ne_50m_populated_places.SHX. Set SHA
fiona DriverError: Failed to open dataset (flags=68): broken/no_shx/ne_50m_populated_places.shp
pyogrio names the missing .shx and the option that restores it; Fiona reports only that it could not open the dataset. If Fiona is not installed, engine="fiona" raises an ImportError, which is expected with GeoPandas 1.0 and later.
8. Test the shapefile in QGIS or another GIS tool
A second reader separates a damaged file from a Python problem. If the file does not open in QGIS either, it is incomplete or damaged. If it opens in QGIS but fails in Python, look at your path, your environment or the encoding. QGIS uses GDAL too, so a file that loads there but shows no attribute table has the same missing-.dbf problem as above.
9. Check what you got after reading
Several of the failures above return a GeoDataFrame without complaint. A short check after every read of a file you did not produce yourself catches all of them:
def check(gdf, expected_rows=None):
problems = []
if expected_rows is not None and len(gdf) != expected_rows:
problems.append(f"{len(gdf)} rows, expected {expected_rows}")
if gdf.geometry.isna().any():
problems.append(f"{gdf.geometry.isna().sum()} null geometries")
if len(gdf.columns) == 1:
problems.append("no attribute columns")
if gdf.crs is None:
problems.append("no CRS")
return problems or ["looks complete"]
for label, path in [("original", "data/places/ne_50m_populated_places.shp"), ("no .dbf", without("dbf")),
("no .prj", without("prj")), ("half .shp", cut("shp", 0.5))]:
print(f"{label:9}", check(gpd.read_file(path), expected_rows=1251))
original ['looks complete']
no .dbf ['no attribute columns']
no .prj ['no CRS']
half .shp ['628 null geometries']
It does not catch the garbled names from step 5; for text, look at a few values that contain accents.
Multi-layer zips and checking parts first
The data used on this page
- Natural Earth populated places β
ne_50m_populated_places, 1:50 million, 1,251 points, as a shapefile with.shp,.shx,.dbf,.prjand a UTF-8.cpg. - Geofabrik's Rutland extract β
rutland-260101-free.shp.zip, OpenStreetMap for England's smallest county as one ZIP of 18 shapefiles, as Geofabrik extracted it on 1 January 2026; the dated file does not change, so the counts here reproduce.
The broken copies in the steps above are made from these in a broken/ folder; nothing is downloaded twice.
import io
import os
import zipfile
import geopandas as gpd
import requests
os.makedirs("data", exist_ok=True)
os.makedirs("broken", exist_ok=True)
if not os.path.exists("data/places/ne_50m_populated_places.shp"):
reply = requests.get("https://naciscdn.org/naturalearth/50m/cultural/ne_50m_populated_places.zip",
headers={"User-Agent": "spatialworkflow.io guide"}, timeout=120)
reply.raise_for_status()
zipfile.ZipFile(io.BytesIO(reply.content)).extractall("data/places")
if not os.path.exists("data/rutland.zip"):
reply = requests.get("https://download.geofabrik.de/europe/united-kingdom/england/rutland-260101-free.shp.zip",
timeout=300) # follows Geofabrik's redirect to the dated file
reply.raise_for_status()
open("data/rutland.zip", "wb").write(reply.content)
print(sorted(f for f in os.listdir("data/places") if not f.endswith((".html", ".txt"))))
['ne_50m_populated_places.cpg', 'ne_50m_populated_places.dbf', 'ne_50m_populated_places.prj', 'ne_50m_populated_places.shp', 'ne_50m_populated_places.shx']
Example 1: Read every layer of a multi-layer ZIP
import geopandas as gpd
import pyogrio
layers = pyogrio.list_layers("data/rutland.zip")
counts = {name: pyogrio.read_info("data/rutland.zip", layer=name)["features"] for name, _ in layers}
for name, n in sorted(counts.items(), key=lambda item: -item[1])[:5]:
print(f"{name:34} {n:>6,}")
roads = gpd.read_file("data/rutland.zip", layer="gis_osm_roads_free_1")
print(len(roads) == counts["gis_osm_roads_free_1"], roads.crs)
gis_osm_roads_free_1 7,292
gis_osm_buildings_a_free_1 5,513
gis_osm_landuse_a_free_1 2,405
gis_osm_natural_free_1 649
gis_osm_pois_a_free_1 538
True EPSG:4326
pyogrio.read_info() counts features without reading them, which is the quickest way to see what an archive holds.
Example 2: Check the parts before reading
from pathlib import Path
shp = Path("data/places/ne_50m_populated_places.shp")
for ext in [".shp", ".shx", ".dbf", ".prj", ".cpg"]:
part = shp.with_suffix(ext)
size = f"{part.stat().st_size:,} bytes" if part.exists() else "MISSING"
print(f"{part.name:32} {size}")
print("encoding in .cpg:", shp.with_suffix(".cpg").read_text().strip())
ne_50m_populated_places.shp 35,128 bytes
ne_50m_populated_places.shx 10,108 bytes
ne_50m_populated_places.dbf 8,229,743 bytes
ne_50m_populated_places.prj 145 bytes
ne_50m_populated_places.cpg 5 bytes
encoding in .cpg: UTF-8
Example 3: Read only the attribute table
import pyogrio
table = pyogrio.read_dataframe("data/places/ne_50m_populated_places.shp", read_geometry=False,
columns=["NAME", "ADM0NAME", "POP_MAX"])
print(type(table).__name__, table.shape)
print(table.nlargest(3, "POP_MAX").to_string(index=False))
DataFrame (1251, 3)
NAME ADM0NAME POP_MAX
Tokyo Japan 35676000
New York United States of America 19040000
Mexico City Mexico 19028000
read_geometry=False returns a plain DataFrame from the .dbf alone, which is a quick way to inspect a large shapefile's fields.
Example 4: Catch and inspect the read error
import geopandas as gpd
for path in ["data/places/ne_50m_populated_place.shp", "broken/cut_shp_0/ne_50m_populated_places.shp"]:
try:
gpd.read_file(path)
except Exception as err:
print(f"{type(err).__module__}.{type(err).__name__}: {str(err)[:90]}")
pyogrio.errors.DataSourceError: data/places/ne_50m_populated_place.shp: No such file or directory
pyogrio.errors.DataSourceError: 'broken/cut_shp_0/ne_50m_populated_places.shp' not recognized as being in a supported file
Both are pyogrio.errors.DataSourceError β one for a path that does not exist, one for a file that exists but is empty β so read the message, not only the type.
Loud failures and quiet ones
Most shapefile read problems in GeoPandas fall into two groups, and the second is the one to worry about:
- loud failures: a path that does not exist, a missing
.shx, a zero-byte.shp. GDAL refuses to open the file and says why (pyogrio passes the message on; Fiona often does not). - silent failures: a missing or empty
.dbf(no attributes), a missing.prj(no CRS), a missing.cpgon a non-Latin-1 file (garbled text), a truncated.shp(rows without geometry), and a multi-layer ZIP read withoutlayer=(the wrong layer). Each returns a GeoDataFrame.
A smaller group of problems happens after the file opens. In those cases, the shapefile is readable, but the data still looks wrong because of invalid geometries, null shapes, or CRS problems.
The fastest diagnostic workflow is:
- verify the path
- verify the shapefile parts and their sizes
- name the layer when reading from an archive
- check rows, null geometries, columns and CRS after reading
- check a few accented values, and pass
encoding=if they are wrong
Network drives, old files and field names
Reading shapefiles from network drives
Network paths can fail because of permissions, sync delays, or file locks. If possible, copy the shapefile to a local folder and test again.
Very old shapefiles
Older shapefiles often have no .cpg and a Windows code page in the .dbf. Most accented letters read correctly as Latin-1, which hides the problem until a character outside Latin-1 β a dash, a curly quote, the euro sign β turns into a control character (step 5).
Shapefile field name limits
Shapefiles limit field names to 10 characters. This does not stop reading, but names truncated at export (population to populatio) no longer match the code that expects them.
When the file opens but data looks wrong
A successful read does not guarantee correct data. Check:
gdf.crs- null geometries
- invalid geometries
- missing or corrupted attributes
This is especially important before spatial joins, reprojection, or export.
Internal links
- How to Fix CRS Mismatch in GeoPandas
- How to Speed Up GeoPandas: Tips for Large Datasets
- Fixing Memory Errors in GeoPandas When Working with Large Files
FAQ
Why does GeoPandas say a shapefile does not exist when the file is in the folder?
Usually because the code is pointing to the wrong path, wrong filename, or wrong working directory. Print the full resolved path and confirm you are passing the .shp file itself.
Can GeoPandas read a shapefile if the .shx or .dbf file is missing?
Without the .shx, pyogrio refuses to open it and tells you to set SHAPE_RESTORE_SHX=YES, which rebuilds the index from the .shp. Without the .dbf, it reads every geometry and silently returns no attribute columns β so check the columns after reading.
Should I use fiona or pyogrio to read shapefiles in GeoPandas?
Use pyogrio, the default since GeoPandas 1.0. Both engines use GDAL, so they succeed and fail on the same files, but pyogrio's error messages are more specific: for a missing .shx it names the file and the fix, where Fiona says only Failed to open dataset.
Why does the shapefile open in QGIS but fail in GeoPandas?
That usually points to the path or the environment rather than the file, since QGIS and GeoPandas both read shapefiles through GDAL. Print the resolved path, and compare what QGIS shows with the row count, columns and CRS you get in Python.
Can a corrupted or partially downloaded shapefile cause read_file() to fail?
Yes β and a partial download may not fail at all. A .shp cut to half its length still loaded all 1,251 rows of Natural Earth's populated places, with 628 of them missing their geometry and no warning. A zero-byte .shp fails to open.
How do I read a shapefile directly from a ZIP without extracting it first?
Pass the ZIP itself: gpd.read_file("data/roads.zip"). If the archive holds more than one layer, add layer="name" (list them with pyogrio.list_layers()), or point at a member with zip://data/roads.zip!roads.shp; otherwise you get the first layer and a warning.
How do I fix garbled accented characters in shapefile attributes?
The .dbf is being decoded with the wrong codec, usually because the .cpg is missing and GDAL fell back to Latin-1. BesanΓΒ§on means the file is UTF-8: pass encoding="utf-8". Correct letters but stray control characters where dashes or quotes should be mean Windows-1252: pass encoding="cp1252".
Can GeoPandas read a shapefile with more than one layer?
A single .shp holds only one layer, so there is nothing to select. Multi-layer handling with the layer= argument applies to containers like GeoPackage and File Geodatabase, not shapefiles.
Why do I get a DataSourceError or DriverError when reading a shapefile?
DataSourceError (pyogrio) and DriverError (Fiona) mean GDAL could not open the data source at all: typically a wrong path, a missing .shx, or a zero-byte or non-shapefile file with a .shp name. A missing .dbf does not cause it. Confirm the resolved path exists and that the required sidecar files are present before retrying.
How can I read only the attribute table of a shapefile without loading geometry?
Use pyogrio.read_dataframe("data.shp", read_geometry=False) to get a plain DataFrame of the fields. This is faster when you only need to inspect or filter the .dbf attributes.