You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Anaconda的Jupyter中使用Geopandas导入Shapefile时出现错误

Fixing "DLL load failed while importing ogrext" Error When Using geopandas.read_file()

I've run into this exact issue before with Anaconda and geopandas—this DLL error almost always boils down to incompatible dependencies or a messy installation of Fiona (the library geopandas relies on for reading shapefiles). Let's walk through how to fix it step by step:

Step 1: Clean up existing installations

First, we need to remove any potentially conflicting versions of geopandas and Fiona. Mixed installs via conda and pip are usually the culprit here, so let's uninstall both completely:

# Uninstall via conda first
conda uninstall -y geopandas fiona

# Make sure pip doesn't leave any leftovers
pip uninstall -y geopandas fiona

Step 2: Reinstall using conda-forge

The conda-forge channel maintains pre-built packages with proper dependency handling for geospatial libraries. This will avoid the DLL missing issue entirely:

conda install -c conda-forge geopandas

This command will automatically install Fiona along with all its required dependencies (like GDAL) in a way that works seamlessly with your Anaconda environment.

Step 3: If problems persist, use a fresh virtual environment

Sometimes old environments have hidden dependency conflicts that are hard to track down. Create a clean environment specifically for geospatial work:

# Create a new environment (Python 3.9 is highly compatible with current geopandas versions)
conda create -n geo_workspace python=3.9 -c conda-forge
conda activate geo_workspace

# Install geopandas in the fresh environment
conda install geopandas

Step 4: Verify the fix

Open your Jupyter notebook again and run your code (I added a small tweak to print only the first few rows for sanity):

import geopandas as gpd
gdf = gpd.read_file('C:\\Downloads\\Temp\\shapefile\\regions.shp')
print(gdf.head())
gdf.plot()

If you see the GeoDataFrame output and a plot renders without errors, you're all set!

Quick note:

Avoid mixing conda and pip for geospatial packages like geopandas, Fiona, or GDAL. Pip's versions often don't account for Anaconda's DLL structure, leading to exactly this kind of error. Stick to conda-forge for reliable, conflict-free installs.

内容的提问来源于stack exchange,提问作者Codak

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 16:14:09