ImportError: DLL load failed while importing _base: 找不到指定的程序。
采用Conda安装的环境
conda create -n raster_env python=3.10
conda activate raster_env
conda install -c conda-forge rasterio gdal
conda list gdal
# Name Version Build Channel
gdal 3.6.2 py310he1c868a_9
libgdal 3.6.2 he0cae08_9
conda list rasterio
# packages in environment at D:\CondaEnvs\NTL_extract_py10:
#
# Name Version Build Channel
rasterio 1.4.3 py310he5c4563_0
有网上建议:https://stackoverflow.com/questions/55596662/rasterio-and-gdal-dll-load-fail-in-pycharm
https://gis.stackexchange.com/questions/417733/unable-to-import-python-rasterio-package-even-though-it-is-installed
from osgeo import gdalimport rasterio
你的 GDAL Python 模块(from osgeo import gdal
)加载失败,原因是找不到底层依赖的 gdalXXX.dll
文件。
在 Python ≥ 3.8 的 Windows 系统中,DLL 不再从 PATH
自动加载。
On Windows, with Python >= 3.8, DLLs are no longer imported from the PATH.
ImportError: DLL load failed while importing _gdal: 找不到指定的程序。 On Windows, with Python >= 3.8, DLLs are no longer imported from the PATH. If gdalXXX.dll is in the PATH, then set the USE_PATH_FOR_GDAL_PYTHON=YES environment variable to feed the PATH into os.add_dll_directory().
参考https://zhuanlan.zhihu.com/p/603881337
解决的办法将路径放入path里面:
在Pycharm里面导入os时,将路径加入到path,再导入rasterio
import os os.environ["PATH"] =r"D:\CondaEnvs\NTL_extract_py10\Lib\site-packages\osgeo" os.environ["PYTHONPATH"] = r"D:\CondaEnvs\NTL_extract_py10\Lib\site-packages\osgeo;"+os.environ["PATH"] os.environ['USE_PATH_FOR_GDAL_PYTHON'] = 'YES'
import rasterio