You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

安装xesmf后测试报错:找不到ESMF模块该如何解决?

问题

按照xesmf官方安装指引创建conda环境并安装相关库:

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

所有库安装成功,但执行测试命令:

pip install pytest
pytest -v --pyargs xesmf

出现错误:ModuleNotFoundError: No module named 'ESMF'。单独测试esmf库:

pytest -v --pyargs esmf

同样报错:ERROR: module or package not found: esmf (missing __init__.py?)

解决方法
  • 优先用conda安装pytest,避免pip和conda的环境冲突:
    # 若已用pip安装pytest,先卸载
    pip uninstall -y pytest
    # 用conda重新安装
    conda install -c conda-forge pytest
    
  • 强制重新安装xesmf及依赖的ESMF库,确保conda正确处理依赖关联:
    conda install -c conda-forge xesmf esmf --force-reinstall
    
  • 无需单独针对esmf包运行测试,直接执行xesmf的测试即可:
    pytest -v --pyargs xesmf
    
  • 若问题仍存在,检查ESMF环境变量是否正确配置:
    • Linux/macOS:
      echo $ESMF_DIR
      # 若输出为空,手动设置路径
      export ESMF_DIR=$CONDA_PREFIX/lib/esmf
      
    • Windows:
      echo %ESMF_DIR%
      # 若输出为空,手动设置路径
      set ESMF_DIR=%CONDA_PREFIX%\Library\lib\esmf
      

内容的提问来源于stack exchange,提问作者Diego Santos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 23:09:58