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

**URL:** <https://openradar.discourse.group/t/attributeerror-module-osgeo-osr-is-not-installed/84>\
**Category:** Openradar\
**Tags:** projects, wradlib, data\
**Created:** [November 3, 2022, 7:02am UTC](https://openradar.discourse.group/t/attributeerror-module-osgeo-osr-is-not-installed/84 "2022-11-03T07:02:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SandeepAllampalli](https://yyz2.discourse-cdn.com/free1/user_avatar/openradar.discourse.group/sandeepallampalli/32/17_2.png) [@SandeepAllampalli](https://openradar.discourse.group/u/SandeepAllampalli)\
**Post date:** [November 3, 2022, 7:02am UTC](https://openradar.discourse.group/t/attributeerror-module-osgeo-osr-is-not-installed/84/1 "2022-11-03T07:02:39Z")

</div>

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’)

```auto
comp = []
for f in os.listdir(src_path):
    comp_ = wrl.io.open_radolan_dataset(src_path+f)
    comp.append(comp_)

```

```auto
for f in os.listdir(src_path):
    comp_ = wrl.io.open_radolan_dataset(src_path+f)
    comp.append(comp_)

```

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

~\anaconda3\envs\wradlib\lib\site-packages\wradlib\io\radolan.py 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)
   1338 
   1339 

~\anaconda3\envs\wradlib\lib\site-packages\xarray\backends\api.py 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)
    537 
    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\backends.py 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\store.py 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()
     28 

~\anaconda3\envs\wradlib\lib\site-packages\xarray\backends\common.py 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\backends.py 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 )
    159 

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

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

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

~\anaconda3\envs\wradlib\lib\site-packages\wradlib\util.py in __getattr__ (self, name)
     71 "installation.html#optional-dependencies"
     72 )
---> 73 raise AttributeError(
     74 f"Module '{self.name}' 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 https://docs.wradlib.org/en/stable/installation.html#optional-dependencies
for further instructions.

```

---

<div class="post-metadata">

**Author:** ![kmuehlbauer](https://yyz2.discourse-cdn.com/free1/user_avatar/openradar.discourse.group/kmuehlbauer/32/439_2.png) [@kmuehlbauer](https://openradar.discourse.group/u/kmuehlbauer)\
**Post date:** [November 3, 2022, 9:38am UTC](https://openradar.discourse.group/t/attributeerror-module-osgeo-osr-is-not-installed/84/2 "2022-11-03T09:38:41Z")

</div>

Hi @SandeepAllampalli,

can you try to import just GDAL in your environment?

```python
from osgeo import osr

```

---

<div class="post-metadata">

**Author:** ![adithiyrnair](https://yyz2.discourse-cdn.com/free1/user_avatar/openradar.discourse.group/adithiyrnair/32/84_2.png) [@adithiyrnair](https://openradar.discourse.group/u/adithiyrnair)\
**Post date:** [November 3, 2022, 10:01am UTC](https://openradar.discourse.group/t/attributeerror-module-osgeo-osr-is-not-installed/84/3 "2022-11-03T10:01:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![SandeepAllampalli](https://yyz2.discourse-cdn.com/free1/user_avatar/openradar.discourse.group/sandeepallampalli/32/17_2.png) [@SandeepAllampalli](https://openradar.discourse.group/u/SandeepAllampalli)\
**Post date:** [November 3, 2022, 11:23am UTC](https://openradar.discourse.group/t/attributeerror-module-osgeo-osr-is-not-installed/84/4 "2022-11-03T11:23:34Z")

</div>

Hi @adithiyrnair ,

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