当想要使用xr.open_mfdataset读取多个nc文件时,输入
files = '...\\201901-201906\\*.nc'
dataset_AVISO = xr.open_mfdataset(files,parallel=True)
运行后出现报错:
Process finished with exit code -1073741571 (0xC00000FD)
debug后,出现报错:
D:\app\python\python310\lib\site-packages\xarray\backends\plugins.py:110: RuntimeWarning: 'netcdf4' fails while guessing
warnings.warn(f"{engine!r} fails while guessing", RuntimeWarning)
D:\app\python\python310\lib\site-packages\xarray\backends\plugins.py:110: RuntimeWarning: 'scipy' fails while guessing
warnings.warn(f"{engine!r} fails while guessing", RuntimeWarning)
D:\app\python\python310\lib\site-packages\xarray\backends\plugins.py:119: RuntimeWarning: 'netcdf4' fails while guessing
warnings.warn(f"{engine!r} fails while guessing", RuntimeWarning)
D:\app\python\python310\lib\site-packages\xarray\backends\plugins.py:119: RuntimeWarning: 'h5netcdf' fails while guessing
warnings.warn(f"{engine!r} fails while guessing", RuntimeWarning)
D:\app\python\python310\lib\site-packages\xarray\backends\plugins.py:119: RuntimeWarning: 'scipy' fails while guessing
warnings.warn(f"{engine!r} fails while guessing", RuntimeWarning)
Traceback (most recent call last):
File "D:\app\python\python310\lib\code.py", line 90, in runcode
exec(code, self.locals)
File "", line 1, in <module>
File "D:\app\python\python310\lib\site-packages\xarray\backends\api.py", line 479, in open_dataset
engine = plugins.guess_engine(filename_or_obj)
File "D:\app\python\python310\lib\site-packages\xarray\backends\plugins.py", line 148, in guess_engine
raise ValueError(error_msg)
ValueError: did not find a match in any of xarray's currently installed IO backends ['netcdf4', 'scipy']. Consider explicitly selecting one of the installed engines via the ``engine`` parameter, or installing additional IO dependencies, see:
https://docs.xarray.dev/en/stable/getting-started-guide/installing.html
https://docs.xarray.dev/en/stable/user-guide/io.html
Process finished with exit code -1073741819 (0xC0000005)
从报错可知出错原因在于: did not find a match in any of xarray’s currently installed IO backends [‘netcdf4’, ‘scipy’]. Consider explicitly selecting one of the installed engines via the engine
parameter, or installing additional IO dependencies
但是博主已经安装了netcdf4和scipy两个库,在看到网友分享的方案后,改成
dataset_AVISO = xr.open_mfdataset(files,engine='netcdf4')
仍然不成功。
在一番尝试后,最后发现只要修改成这样,代码即可运行成功:
dataset_AVISO = xr.open_mfdataset(files)