2

Recently I'm trying to study about netCDF4 in Python to deal with climate na data file, however, weather I tried import netCDF4 as nc or from netCDF4 import Dataframe, it just can't read the nc file I was trying to open, also the problem said module 'netCDF4' has no 'Dataset' member, and no name 'Dataset' in module 'netCDF4', I pip install netCDF4 before, so don't know how to solve this problem.

The code is below:

import netCDF4 as nc 
from netCDF4 import Dataset



file = 'D:/ncllll/wrfout_d04_2020-03-26_00_00_00.nc'
f = nc.Dataset(file)
print(f.variables)

all_vars = f.variables.keys()  
print(len(all_vars))  #

all_vars_info = f.variables.items()  
print(type(all_vars_info))   
print(len(all_vars_info))   #
all_vars_info = list(all_vars_info)  

And the problems are:

  1. module 'netCDF4' has no 'Dataset' member
  2. no name 'Dataset' in module 'netCDF4'

The print result is:

{}
0
<class 'dict_items'>
0
halfer
  • 19,824
  • 17
  • 99
  • 186
landy
  • 21
  • 2
  • 1
    if you `import netCDF4 as nc`, you don't need to import `Dataset` separately. the other way around, if you only need `Dataset`, you don't need to import the whole package. – FObersteiner Sep 25 '20 at 07:37
  • Thank you for help, however, I tried to import them seprately, still got the same problem and print result. – landy Sep 25 '20 at 08:41
  • ok this is strange... did you make sure you have the [other requirements](http://unidata.github.io/netcdf4-python/netCDF4/index.html) installed on your system? did the `pip install` run successfully? – FObersteiner Sep 25 '20 at 09:01
  • Ye IKR, so strange, i did pip install, and i just tried again in cmd, it showed:C:\WINDOWS\system32>pip install netCDF4 Requirement already satisfied: netCDF4 in d:\ana\lib\site-packages (1.5.4) Requirement already satisfied: cftime in d:\ana\lib\site-packages (from netCDF4) (1.2.1) Requirement already satisfied: numpy>=1.9 in d:\ana\lib\site-packages (from netCDF4) (1.16.5) – landy Sep 25 '20 at 09:04

0 Answers0