1

I am new to python, and trying to run Metpy tutorial with xarray, before its ok but after I update xarray to newer version then it show an error

I have tried to create another environment in anaconda prompt, and install every module including metpy (xarray is already included)

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

I want to get the exact result from metpy tutorial, but module not found when importing metpy module create an error that failed the tutorial, thanks for your help

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

3 Answers3

5

This issue is due to Xarray's update to 0.12.2. A new release of MetPy just went out yesterday, so these issues have been resolved. If you just upgrade MetPy, everything should work again: pip install --upgrade metpy

zbruick
  • 316
  • 1
  • 9
0

Go to C:\ProgramData\Anaconda3\envs\cobaxarray\lib\site-packages\metpy\xarray.py

find the line from xarray.core.accessors import DatetimeAccessor

change it to from xarray.core.accessor_dt import DatetimeAccessor

Sıddık Açıl
  • 957
  • 8
  • 18
0

I had to dereference anaconda3 in my .bashrc file, then reinstall the 2020 version of anaconda3 and let it initialize itself in .bashrc.
Then I did...

conda update --all
conda update spyder

...then I did these both again to make sure everything got installed.

Then...

conda install -c conda-forge metpy

It installed a good version of everything (including xarray) and now the examples in the MetPy Gallery work as advertised!

RJ Adriaansen
  • 9,131
  • 2
  • 12
  • 26