尝试读取Python3.7中的netcdf文件时出现未知文件格式错误

2024-05-12 19:58:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用Spyder(python 3.7)从Anacondas包中读取netcdf文件,得到错误消息:

[Errno -51] NetCDF: Unknown file format: b'AMSR2-MBT_v2r0_GW1_s201907081630360_e201907081809340_c201907081825230.nc'

我尝试过使用导入操作系统和其他方法设置路径。它可能试图使用路径作为文件名,或者netCDF安装有问题

我还尝试将AMSR2_path作为MBT_data变量加入到文件名中,但没用。在

import os
import netCDF4

#os.getcwd() #Use to check the current location 
#os.chdir() #Use to change directory
AMSR2_path = os.path.join(os.getcwd()) #Returns the current working 
directory

MBT_data = "AMSR2- 
MBT_v2r0_GW1_s201907081630360_e201907081809340_c201907081825230.nc"
print(type(MBT_data)) 

data = netCDF4.Dataset(MBT_data,"r")
print(data.variables)

Here是实际的文件。在


Tags: 文件pathimport路径dataos文件名nc