'how to set the USE_PATH_FOR_GDAL_PYTHON=YES environment variable to feed the PATH into os.add_dll_directory()

I've been running GDAL through python on anaconda for years with no problem. Today when I tried to import gdal I got this error code:

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().

I've been looking for a solution to this but can't seem to figure out how to fix this. Anybody has a solution?



Solution 1:[1]

use: from osgeo import gdal

instead of: import gdal

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 B-C B.