ModuleNotFoundError:没有名为“ xarray.core.accessors”的模块

时间:2019-07-05 12:03:04

标签: python python-3.x python-xarray metpy

我是python的新手,并尝试使用xarray运行Metpy教程,在确定之前,但在将xarray更新为较新版本后,它显示错误

我试图在anaconda提示符下创建另一个环境,并安装包括metpy的每个模块(已经包含xarray)

import metpy
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-4fe739b01247> in <module>
----> 1 import metpy

C:\ProgramData\Anaconda3\envs\cobaxarray\lib\site-packages\metpy\__init__.py in <module>
     13 
     14 from ._version import get_versions  # noqa: E402
---> 15 from .xarray import *  # noqa: F401, F403
     16 __version__ = get_versions()['version']
     17 del get_versions

C:\ProgramData\Anaconda3\envs\cobaxarray\lib\site-packages\metpy\xarray.py in <module>
     11 
     12 import xarray as xr
---> 13 from xarray.core.accessors import DatetimeAccessor
     14 from xarray.core.indexing import expanded_indexer
     15 from xarray.core.utils import either_dict_or_kwargs, is_dict_like

ModuleNotFoundError: No module named 'xarray.core.accessors'
This is the xarray installed versions outside my environment
INSTALLED VERSIONS
------------------
commit: None
python: 3.7.3 | packaged by conda-forge | (default, Mar 27 2019, 23:18:50) [MSC v.1900 64 bit (AMD64)]
python-bits: 64
OS: Windows
OS-release: 8.1
machine: AMD64
processor: Intel64 Family 6 Model 69 Stepping 1, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
libhdf5: 1.10.4
libnetcdf: 4.6.2

xarray: 0.12.2
pandas: 0.24.2
numpy: 1.16.3
scipy: 1.2.1
netCDF4: 1.5.1.2
pydap: None
h5netcdf: None
h5py: 2.9.0
Nio: None
zarr: None
cftime: 1.0.3.4
nc_time_axis: 1.1.0
PseudonetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: 1.2.1
dask: 1.2.2
distributed: 1.28.1
matplotlib: 3.1.0
cartopy: 0.17.0
seaborn: 0.9.0
numbagg: None
setuptools: 41.0.1
pip: 19.1.1
conda: 4.7.5
pytest: 4.5.0
IPython: 7.5.0
sphinx: 2.0.1
This is the installed version of xarray inside my environment
INSTALLED VERSIONS
------------------
commit: None
python: 3.7.3 | packaged by conda-forge | (default, Jul  1 2019, 22:01:29) [MSC v.1900 64 bit (AMD64)]
python-bits: 64
OS: Windows
OS-release: 8.1
machine: AMD64
processor: Intel64 Family 6 Model 69 Stepping 1, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
libhdf5: None
libnetcdf: None

xarray: 0.12.2
pandas: 0.24.2
numpy: 1.16.4
scipy: 1.2.1
netCDF4: None
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: None
nc_time_axis: None
PseudonetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: 3.1.1
cartopy: 0.17.0
seaborn: None
numbagg: None
setuptools: 41.0.1
pip: 19.1.1
conda: None
pytest: None
IPython: 7.6.1
sphinx: None

我想从metpy教程中获得准确的结果,但是在导入metpy模块时找不到模块,导致该教程失败的错误,感谢您的帮助

3 个答案:

答案 0 :(得分:3)

此问题归因于Xarray更新至0.12.2。 MetPy的新版本昨天才发布,因此这些问题已得到解决。如果您只是升级MetPy,则所有操作都应再次起作用:pip install --upgrade metpy

答案 1 :(得分:0)

转到C:\ProgramData\Anaconda3\envs\cobaxarray\lib\site-packages\metpy\xarray.py

找到行from xarray.core.accessors import DatetimeAccessor

将其更改为from xarray.core.accessor_dt import DatetimeAccessor

答案 2 :(得分:0)

我不得不在我的 anaconda3 文件中取消引用 .bashrc,然后重新安装 2020 版的 anaconda3 并让它在 .bashrc 中自行初始化。
然后我做了...

conda update --all
conda update spyder

...然后我又做了一遍以确保所有东西都安装好了。

那么……

conda install -c conda-forge metpy

它安装了所有东西的好版本(包括 xarray),现在 MetPy Gallery 中的示例如宣传的那样工作!