python中gdal导入问题(环境变量)

问题遇到的现象和发生背景

尝试运行 conda update conda 命令以后,在 spyder 中尝试通过 from osgeo import gdal 导入 gdal,出现错误“ImportError: DLL load failed while importing _gdal: 找不到指定的模块。”

运行结果及报错内容
from osgeo import gdal
Traceback (most recent call last):

  File ~\anaconda3\lib\site-packages\osgeo\__init__.py:29 in swig_import_helper
    return importlib.import_module(mname)

  File ~\anaconda3\lib\importlib\__init__.py:127 in import_module
    return _bootstrap._gcd_import(name[level:], package, level)

  File _bootstrap>:1030 in _gcd_import

  File _bootstrap>:1007 in _find_and_load

  File _bootstrap>:986 in _find_and_load_unlocked

  File _bootstrap>:666 in _load_unlocked

  File _bootstrap>:565 in module_from_spec

  File _bootstrap_external>:1173 in create_module

  File _bootstrap>:228 in _call_with_frames_removed

ImportError: DLL load failed while importing _gdal: 找不到指定的模块。


During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  Input In [4] in 1>
    from osgeo import gdal

  File ~\anaconda3\lib\site-packages\osgeo\__init__.py:45 in 
    _gdal = swig_import_helper()

  File ~\anaconda3\lib\site-packages\osgeo\__init__.py:41 in swig_import_helper
    raise ImportError(traceback_string + '\n' + msg)

ImportError: Traceback (most recent call last):
  File "C:\Users\p676p\anaconda3\lib\site-packages\osgeo\__init__.py", line 29, in swig_import_helper
    return importlib.import_module(mname)
  File "C:\Users\p676p\anaconda3\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 1030, in _gcd_import
  File "", line 1007, in _find_and_load
  File "", line 986, in _find_and_load_unlocked
  File "", line 666, in _load_unlocked
  File "", line 565, in module_from_spec
  File "", line 1173, in create_module
  File "", line 228, in _call_with_frames_removed
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().

我的解答思路和尝试过的方法

不知道如何解决

我想要达到的结果


请问解决了吗,咋搞定的

请问你解决了嘛,和你的报错一模一样

重新装gdal试试