AttributeError: Module 'osgeo.osr' is not installed

Hello there,

Python version: 3.9.12
wradlib version: 1.17.0

I tried to reinstall the latest version of wradlib using conda in my virtual environment. It got successfully installed. When I was trying to read the data set I was getting the following error. I understand this is being caused because of the installation problem of gdal package in the virtual environment. When I run “conda list” in the shell it displays list of packages installed. Here I can see gdal(version 3.4.1) installed. But when I run in python and tried to import the module gdal, I get this error.(ModuleNotFoundError: No module named ‘gdal’)

comp = []
for f in os.listdir(src_path):
    comp_ =

for f in os.listdir(src_path):
    comp_ =
AttributeError                            Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_6792\ in <cell line: 1>()
      1 for f in os.listdir(src_path):
----> 2     comp_ =
      3     comp.append(comp_)

~\anaconda3\envs\wradlib\lib\site-packages\wradlib\io\ in open_radolan_dataset(filename_or_obj, **kwargs)
   1335     }
   1336     kwargs["backend_kwargs"] = backend_kwargs
-> 1337     return xr.open_dataset(filename_or_obj, engine="radolan", **kwargs)

~\anaconda3\envs\wradlib\lib\site-packages\xarray\backends\ in open_dataset(filename_or_obj, engine, chunks, cache, decode_cf, mask_and_scale, decode_times, decode_timedelta, use_cftime, concat_characters, decode_coords, drop_variables, inline_array, backend_kwargs, **kwargs)
    538     overwrite_encoded_chunks = kwargs.pop("overwrite_encoded_chunks", None)
--> 539     backend_ds = backend.open_dataset(
    540         filename_or_obj,
    541         drop_variables=drop_variables,

~\anaconda3\envs\wradlib\lib\site-packages\wradlib\io\ in open_dataset(self, filename_or_obj, mask_and_scale, decode_times, concat_characters, decode_coords, drop_variables, use_cftime, decode_timedelta, fillmissing, copy, ancillary)
    199         store_entrypoint = StoreBackendEntrypoint()
    200         with close_on_error(store):
--> 201             ds = store_entrypoint.open_dataset(
    202                 store,
    203                 mask_and_scale=mask_and_scale,

~\anaconda3\envs\wradlib\lib\site-packages\xarray\backends\ in open_dataset(self, store, mask_and_scale, decode_times, concat_characters, decode_coords, drop_variables, use_cftime, decode_timedelta)
     24         decode_timedelta=None,
     25     ):
---> 26         vars, attrs = store.load()
     27         encoding = store.get_encoding()

~\anaconda3\envs\wradlib\lib\site-packages\xarray\backends\ in load(self)
    126         """
    127         variables = FrozenDict(
--> 128             (_decode_variable_name(k), v) for k, v in self.get_variables().items()
    129         )
    130         attributes = FrozenDict(self.get_attrs())

~\anaconda3\envs\wradlib\lib\site-packages\wradlib\io\ in get_variables(self)
    155     def get_variables(self):
    156         return FrozenDict(
--> 157             (k, self.open_store_variable(k, v)) for k, v in self.ds.variables.items()
    158         )

~\anaconda3\envs\wradlib\lib\site-packages\wradlib\io\ in variables(self)
   1102     def variables(self):
   1103         if self._variables is None:
-> 1104             self._read()
   1105         return self._variables

~\anaconda3\envs\wradlib\lib\site-packages\wradlib\io\ in _read(self)
   1214             proj = projection.create_osr("dwd-radolan-wgs84")
   1215         else:
-> 1216             proj = projection.create_osr("dwd-radolan-sphere")
   1218         xlocs, ylocs = rect.get_radolan_coordinates(

~\anaconda3\envs\wradlib\lib\site-packages\wradlib\georef\ in create_osr(projname, **kwargs)
    146     )
--> 148     proj = osr.SpatialReference()
    150     if projname == "aeqd":

~\anaconda3\envs\wradlib\lib\site-packages\wradlib\ in __getattr__(self, name)
     71             "installation.html#optional-dependencies"
     72         )
---> 73         raise AttributeError(
     74             f"Module '{}' is not installed.\n\n"
     75             "You tried to access function/module/attribute "

AttributeError: Module 'osgeo.osr' is not installed.

You tried to access function/module/attribute 'SpatialReference'
from module 'osgeo.osr'.
This module is optional right now in wradlib.
You need to separately install this dependency.
Please refer to
for further instructions.

Hi @SandeepAllampalli,

can you try to import just GDAL in your environment?

from osgeo import osr

Hello SandeepAllampalli,
I also faced the Same issue follow the following

  1. Make sure you installed Gdal latest version after enabling your environment as
    conda install gdal
  2. Then Execute
    conda upgrade numpy
  3. Restart Kernal

The problem that I found is that Installing Gdal will downgrade the NumPy version so after installation of Gdal you should upgrade numpy

Hi @adithiyrnair ,

That really worked like a gem. Thank you for the help.