How to convert geotiff to netcdf using gdal and python MacOS

My current python version is 3.11.3 on MacOS

First create python environment, then install gdal in the environment

  • create conda environment; I named my environment gdalenv
  • Activate the environment then install gdal
> conda create --name gdalenv
> conda activate gdalenv
> conda install gdal

In python code,

>>from osgeo import gdal
>>gdal.Translate(mynewfile.nc, mytifffile.tiff, format='NetCDF')