Conda install xesmf

Hi,
I was just helping a student to install xesmf on a macbook. I have done this before using conda, and followed the same procedure, but after a seemingly successful install, when the student tries to run:

import xesmf

then we get an error message saying:

ERROR - ModuleNotFoundError: No module named 'ESMF'

I tried following the suggested solution at this Stack Overflow link but had no luck.
Anyone else encountered this problem?

Regards,
David

Hi @dkhutch,
I am on a macbook (Sonoma 14.1.1) and if I install it in a clean environment everything works (so I cannot reproduce the error, unfortunately).

Did you install it in a clean environment?

After trying the suggesgion linked (setting ESMFMKFILE=/path/to/anaconda3/envs/[envname]/lib/esmf.mk) do you always get the same error?

Do you have any traceback for the error, or just that ERROR line?

Thanks @atteggiani ! I will look into it and get back with further information.

Hi David,

This might not be too helpful but I have the same issue with one of my environments, where I receive the following error:

>>> import xesmf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "//anaconda3/envs/analysis/lib/python3.10/site-packages/xesmf/__init__.py", line 4, in <module>
    from .frontend import Regridder, SpatialAverager
  File "//anaconda3/envs/analysis/lib/python3.10/site-packages/xesmf/frontend.py", line 12, in <module>
    from .backend import Grid, LocStream, Mesh, add_corner, esmf_regrid_build, esmf_regrid_finalize
  File "//anaconda3/envs/analysis/lib/python3.10/site-packages/xesmf/backend.py", line 21, in <module>
    import ESMF
ModuleNotFoundError: No module named 'ESMF'

It’s a bit strange – if I create a new environment and install xesmf it works for me without any issues, even if I use the exact same yaml file as the environment that gives the error.

Hi @spencerwong,

Can you please check the content of the //anaconda3/envs/analysis/lib/python3.10/site-packages/xesmf/backend.py file specified by the last call of your Traceback?

In my working environment, that same file at lines 21 to 24 has the following code:

 21 try:
 22     import esmpy as ESMF
 23 except ImportError:
 24     import ESMF

I am wondering if your file has the same, or maybe it only tries to import ESMF without first trying to import esmpy as ESMF.

Also, could you please print the output of the conda list command for your environment in which import xesmf spawns the error?

Hi @atteggiani,

Great point, they do look different. The environment where I get the error just has

import ESMF

at line 21, while the environment where it is working has as in your one

try:
    import esmpy as ESMF
except ImportError:
    import ESMF

I’ve attached the output of conda list from the environment where I get the error (analysis), and also for the newer environment which used the same yaml file, but has no issues (xesmf_failtest_2).

xesmf_failtest_2.txt (23.3 KB)
analysis_list.txt (22.6 KB)

It looks like they have different versions for a lot of the packages, including xesmf.

Thanks!
Spencer

Thanks for the follow up information. Grace has reported that she can also do a “clean” install of xesmf, whereas the one we were trying before had a lot of different packages put together. I suspect the error she was getting is very similar to what @spencerwong identified here. In any case, we have a way of using the package for now.
Regards,
David