Importing a .tif into Jupyter Notebook using python script

Viewed 18

I have been trying to import a .tif into python using the following code:

image = 'location/map_Western_Cape.tif' #use same location as above
geemap.plot_raster(image, cmap='terrain', figsize=(15, 10))

image_Gauteng = 'location/map_Gauteng.tif' #use same location as above
geemap.plot_raster(image, cmap='terrain', figsize=(15, 10))

However, I keep getting this error message:

AttributeError                            Traceback (most recent call last)
Input In [11], in <cell line: 4>()
      1 # Load the .tif from local machine
      3 image = 'C:/Users/kiral/OneDrive - Stellenbosch University/BScHons Global Change/Guy/map_Western_Cape.tif' #use same location as above
----> 4 geemap.plot_raster(image, cmap='terrain', figsize=(15, 10))
      6 image_Gauteng = 'C:/Users/kiral/OneDrive - Stellenbosch University/BScHons Global Change/Guy/map_Gauteng.tif' #use same location as above
      7 geemap.plot_raster(image, cmap='terrain', figsize=(15, 10))

File ~\anaconda3\lib\site-packages\geemap\common.py:12559, in plot_raster(image, band, cmap, proj, figsize, open_kwargs, **kwargs)
  12557 try:
  12558     import pvxarray
> 12559     import rioxarray
  12560     import xarray
  12561 except ImportError:

File ~\anaconda3\lib\site-packages\rioxarray\__init__.py:6, in <module>
      3 __author__ = """rioxarray Contributors"""
      4 __email__ = "alansnow21@gmail.com"
----> 6 import rioxarray.raster_array  # noqa
      7 import rioxarray.raster_dataset  # noqa
      8 from rioxarray._io import open_rasterio  # noqa

File ~\anaconda3\lib\site-packages\rioxarray\raster_array.py:28, in <module>
     14 from typing import (
     15     Any,
     16     Dict,
   (...)
     24     Union,
     25 )
     27 import numpy as np
---> 28 import rasterio
     29 import rasterio.mask
     30 import rasterio.warp

File ~\anaconda3\lib\site-packages\rasterio\__init__.py:44, in <module>
     41 import warnings
     43 import rasterio._loading
---> 44 with rasterio._loading.add_gdal_dll_directories():
     45     from rasterio._show_versions import show_versions
     46     from rasterio._version import gdal_version, get_geos_version, get_proj_version

AttributeError: partially initialized module 'rasterio' has no attribute '_loading' (most likely due to a circular import)

I have tried installing all of the listed modules, but that ended up getting a bunch of errors too.

Could anyone recommend a way to import these tifs?

0 Answers
Related