Python 2.7环境下Conda导入Geopandas报DLL加载错误求助
问题
在Python 2.7环境中导入Geopandas时出现DLL加载错误,操作步骤如下:
conda create --channel conda-forge -n env_test python=2.7 geopandas # 执行成功 conda activate py27env python --version # 输出:Python 2.7.15 # 导入模块 python import geopandas
完整错误栈:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\Administrator\miniconda3\envs\env_test\lib\site-packages\geopandas\__init__.py", line 5, in <module> from geopandas.io.file import read_file # noqa File "C:\Users\Administrator\miniconda3\envs\env_test\lib\site-packages\geopandas\io\file.py", line 6, in <module> import fiona File "C:\Users\Administrator\miniconda3\envs\env_test\lib\site-packages\fiona\__init__.py", line 69, in <module> from fiona.collection import Collection, BytesCollection, vsi_path File "C:\Users\Administrator\miniconda3\envs\env_test\lib\site-packages\fiona\collection.py", line 9, in <module> from fiona.ogrext import Iterator, ItemsIterator, KeysIterator ImportError: DLL load failed: The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail.
环境信息:
- Miniconda 4.12.0
- 系统:Windows Server 2019 / Windows 10(测试均报错,Python 3.9+环境无此问题)
Conda包列表:
# Name Version Build Channel boost-cpp 1.70.0 h099cdad_2 conda-forge ca-certificates 2022.6.15 h5b45459_0 conda-forge certifi 2019.11.28 py27h8c360ce_1 conda-forge click 7.1.2 pyh9f0ad1d_0 conda-forge click-plugins 1.1.1 py_0 conda-forge cligj 0.7.2 pyhd8ed1ab_1 conda-forge curl 7.65.3 h2f83ebf_0 conda-forge enum34 1.1.10 py27h8c360ce_1 conda-forge expat 2.2.9 h2880e7c_2 conda-forge fiona 1.7.13 py27_0 conda-forge freexl 1.0.5 haa51a25_1002 conda-forge gdal 2.2.2 py27h58389d3_1 geopandas 0.6.3 py_0 conda-forge geos 3.6.2 heec837b_2 hdf4 4.2.13 ha32470c_1003 conda-forge hdf5 1.10.1 vc9_2 conda-forge intel-openmp 2022.1.0 h57928b3_3787 conda-forge jpeg 9c h0c8e037_1001 conda-forge kealib 1.4.7 vc9_4 conda-forge krb5 1.16.4 h7fea353_0 conda-forge libblas 3.9.0 8_mkl conda-forge libcblas 3.9.0 8_mkl conda-forge libcurl 7.65.3 h2f83ebf_0 conda-forge libgdal 2.2.2 h75964b3_1 libiconv 1.15 h0c8e037_1006 conda-forge libkml 1.3.0 h59e3451_1010 conda-forge liblapack 3.9.0 8_mkl conda-forge libnetcdf 4.4.1.1 vc9_10 conda-forge libpng 1.6.37 h7a46e7a_0 conda-forge libpq 11.5 h5e4800f_1 conda-forge libspatialindex 1.8.5 h2880e7c_4 conda-forge libspatialite 4.3.0a he01c9b4_1023 conda-forge libssh2 1.8.2 hd5c6ab6_2 conda-forge libtiff 4.0.10 h52ad3ab_1002 conda-forge libxml2 2.9.10 h00b1425_0 conda-forge mkl 2020.4 hb70f87d_311 conda-forge munch 2.5.0 py_0 conda-forge numpy 1.16.5 py27h0d21db5_0 conda-forge openjpeg 2.3.1 hb90df43_1 conda-forge openssl 1.1.1e h0c8e037_0 conda-forge pandas 0.24.2 py27h0e003f4_0 conda-forge pip 20.1.1 pyh9f0ad1d_0 conda-forge proj4 4.9.3 h0c8e037_9 conda-forge pyproj 1.9.5.1 py27he834874_1006 conda-forge python 2.7.15 h2880e7c_1011_cpython conda-forge python-dateutil 2.8.1 py_0 conda-forge python_abi 2.7 1_cp27m conda-forge pytz 2020.1 pyh9f0ad1d_0 conda-forge rtree 0.8.3 py27_0 setuptools 44.0.0 py27_0 conda-forge shapely 1.6.4 py27hc31c106_1000 conda-forge six 1.16.0 pyh6c4a22f_0 conda-forge sqlite 3.30.1 h0c8e037_0 conda-forge tk 8.6.10 h0c8e037_0 conda-forge vc 9 h2eaa2aa_6 vs2008_runtime 9.0.30729.6161 0 conda-forge wheel 0.37.1 pyhd8ed1ab_0 conda-forge wincertstore 0.2 py27_1003 conda-forge xerces-c 3.2.2 hc56fc5f_1004 conda-forge xz 5.2.4 h3cc03e0_1001 conda-forge zlib 1.2.11 h3cc03e0_1006 conda-forge zstd 1.3.3 vc9_1 conda-forge
解决方案
修复Visual C++运行时依赖:
错误提示的"side-by-side configuration is incorrect"通常是VC++运行时库版本不匹配或缺失导致的。当前环境使用vc9(对应VS2008),可尝试:- 卸载现有
vs2008_runtime包后重新安装:conda activate env_test conda remove vs2008_runtime --force conda install vs2008_runtime=9.0.30729.6161 -c conda-forge - 手动下载安装微软官方的Microsoft Visual C++ 2008 SP1 Redistributable Package(匹配系统位数),安装后重启环境再尝试导入。
- 卸载现有
降级Fiona版本:
当前使用的Fiona 1.7.13可能和Python 2.7的VC9环境存在兼容性问题,尝试安装更早的兼容版本:conda activate env_test conda remove fiona --force conda install fiona=1.7.12 -c conda-forge重新构建干净的环境:
现有环境可能存在依赖冲突,删除旧环境后重新创建并指定明确的依赖版本:conda env remove -n env_test conda create -n env_test python=2.7 geopandas=0.6.3 fiona=1.7.12 vs2008_runtime=9.0.30729.6161 -c conda-forge迁移到Python 3环境:
Python 2.7已停止官方支持,Geopandas后续版本也不再维护Python 2.7兼容。若业务允许,建议直接迁移到Python 3.9+环境,彻底避免这类兼容性问题。
内容的提问来源于stack exchange,提问作者Jelphy
相关产品推荐
相关产品推荐

