【python读取nc文件】报错:ValueError: unrecognized engine netcdf4 must be one of: [‘store‘]

写在最前面

尝试2019华为杯E题,但是报错:
ValueError: unrecognized engine netcdf4 must be one of: [‘store’]
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings…

最终解决
【python读取nc文件】报错:ValueError: unrecognized engine netcdf4 must be one of: [‘store‘]_第1张图片

报错1:ValueError: found the following matches with the input file in xarray’s IO backends: [‘netcdf4’, ‘h5netcdf’]. But their dependencies may not be installed, see:

https://docs.xarray.dev/en/stable/user-guide/io.html
https://docs.xarray.dev/en/stable/getting-started-guide/installing.html

参考:https://blog.csdn.net/linxi4165/article/details/118470843

conda install xarray

注意:Python最好3.9以上
【python读取nc文件】报错:ValueError: unrecognized engine netcdf4 must be one of: [‘store‘]_第2张图片

下载链接:
https://pypi.tuna.tsinghua.edu.cn/simple/netcdf4/

下载与系统对应的netCAD4,一定要注意32位还是64位,以及操作系统的类型。

找到python对应版本的
Ctrl+F进行网页搜索
【python读取nc文件】报错:ValueError: unrecognized engine netcdf4 must be one of: [‘store‘]_第3张图片
该文件放到开始conda环境的cmd目录下
在pip>后输入
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple netCDF4-1.5.4-cp39-cp39-win_amd64.whl
加粗部分自行替代成自己下载版本的名字,也就是下载的WHL文件的全名之后等待安装即可。

报错二:ValueError: unrecognized engine netcdf4 must be one of: [‘store’] Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings…

参考:https://blog.csdn.net/showpingzhang/article/details/83384780

代码修改为:

# -*- coding: utf-8 -*-


import netCDF4
from netCDF4 import Dataset
nc_obj=Dataset('e:\\P_CLDAS_RE01_EA16_PRE_HOUR_2015010101.nc')

#查看nc文件有些啥东东
print(nc_obj)
print('---------------------------------------')

#查看nc文件中的变量
print(nc_obj.variables.keys())
for i in nc_obj.variables.keys():
    print(i)
print('---------------------------------------')

#查看每个变量的信息
print(nc_obj.variables['LAT'])
print(nc_obj.variables['LON'])
print(nc_obj.variables['PRCP'])
print('---------------------------------------')

#查看每个变量的属性
print(nc_obj.variables['LAT'].ncattrs())
print(nc_obj.variables['LON'].ncattrs())
print(nc_obj.variables['PRCP'].ncattrs())
print(nc_obj.variables['LAT'].units)
print(nc_obj.variables['LON'].units)
print(nc_obj.variables['PRCP']._Fillvalue)
print('---------------------------------------')

#读取数据值
lat=(nc_obj.variables['LAT'][:])
lon=(nc_obj.variables['LON'][:])
prcp=(nc_obj.variables['PRCP'][:])
print(lat)
print(lon)
print('---------------******-------------------')
print(prcp)

【python读取nc文件】报错:ValueError: unrecognized engine netcdf4 must be one of: [‘store‘]_第4张图片

你可能感兴趣的:(环境配置,python,数据库,开发语言)