xESMF: Installation through conda, import xesmf fails

Hello, I have installed xesmf through conda (I include the other libraries I used) :

conda create -n xesmf_env
conda activate xesmf_env

conda install -c conda-forge xesmf
conda install -c conda-forge dask netCDF4
conda install -c conda-forge matplotlib cartopy jupyterlab

And when I execute import xesmf, I get :

ERROR:
>>> import xesmf
Traceback (most recent call last):
  File "C:\Users\adrie\miniconda3\envs\xesmf_env\lib\site-packages\esmpy\interface\loadESMF.py", line 26, in <module>
    esmfmk = os.environ["ESMFMKFILE"]
  File "C:\Users\adrie\miniconda3\envs\xesmf_env\lib\os.py", line 680, in __getitem__
    raise KeyError(key) from None
KeyError: 'ESMFMKFILE'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\adrie\miniconda3\envs\xesmf_env\lib\site-packages\xesmf\backend.py", line 22, in <module>
    import esmpy as ESMF
  File "C:\Users\adrie\miniconda3\envs\xesmf_env\lib\site-packages\esmpy\__init__.py", line 112, in <module>
    from esmpy.api.esmpymanager import *
  File "C:\Users\adrie\miniconda3\envs\xesmf_env\lib\site-packages\esmpy\api\esmpymanager.py", line 9, in <module>
    from esmpy.interface.cbindings import *
  File "C:\Users\adrie\miniconda3\envs\xesmf_env\lib\site-packages\esmpy\interface\cbindings.py", line 13, in <module>
    from esmpy.interface.loadESMF import _ESMF
  File "C:\Users\adrie\miniconda3\envs\xesmf_env\lib\site-packages\esmpy\interface\loadESMF.py", line 28, in <module>
    raise ImportError('The ESMFMKFILE environment variable is not available.')
ImportError: The ESMFMKFILE environment variable is not available.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\adrie\miniconda3\envs\xesmf_env\lib\site-packages\xesmf\__init__.py", line 4, in <module>
    from .frontend import Regridder, SpatialAverager
  File "C:\Users\adrie\miniconda3\envs\xesmf_env\lib\site-packages\xesmf\frontend.py", line 12, in <module>
    from .backend import Grid, LocStream, Mesh, add_corner, esmf_regrid_build, esmf_regrid_finalize
  File "C:\Users\adrie\miniconda3\envs\xesmf_env\lib\site-packages\xesmf\backend.py", line 24, in <module>
    import ESMF
ModuleNotFoundError: No module named 'ESMF'


ERROR IMPORTING ESMF:
>>> import ESMF
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'ESMF'

This used to work a few months ago, the error appeared when I needed to use the library again since last week.

I tried to revert to an older version (0.6.3) and to install with pip, same issue. 2 other coworkers have tried and faced the same issue on their computer.

Thanks for any help!

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 16

Commits related to this issue

Most upvoted comments

hmm I wonder if the experience with activate/deactivate is different if installing from base environment or from within an environment? Beats me. But Kristen’s comment confirms your solution Pascal. Thank you both!

Thank goodness I found this! This wasn’t easily googleable for some reason but I found this by checking the issues directly.

Have you tried deactivating and re-activating the environment after the installation ?

Simply adding:

conda deactivate
conda activate xesmf_env

If this work, then it’s because you are encountering https://github.com/esmf-org/esmf/issues/117.

ESMF 8.4 had to major breaking changes:

  1. The python package was renamed to esmpy
  2. Importing the fortran wrapper depends on a file that is found through an environment variable which is set when activating the conda environment. Thus, one needs to “activate” before using the package.

Downgrading esmf to 8.3.1 (and not xesmf) will also fix the issue.