-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Import Issue, ModuleNotFoundError: No module named 'ESMF' / Problem on Jupyter #269
Comments
Hi @mchoblet, sorry to hear that... This bug truly is painful. First of all, in the traceback, the very first error is : Traceback (most recent call last)
File ~/miniconda3/envs/xesmf_new_2/lib/python3.11/site-packages/esmpy/interface/loadESMF.py:26
25 try:
---> 26 esmfmk = os.environ["ESMFMKFILE"]
27 except: This line of code just doesn't exist in ESMpy 8.3.1 . If you had a similar issue when downgrading, then it was a different issue. If you try downgrading again, I suggest you post the traceback in this discussion so we can see what is this other bug. You say:
my question is then, what was the other way of importing xesmf ? Is there a way to activate/deactivate an environment that doesn't concern the terminal ? Because that is what the bug is : activating the environment adds a shell variable that points to some configuration file. Thus, the package (ESMpy) becomes unusable outside a shell with this variable. One other trick, is to set this environment variable in the code: import os
from pathlib import Path
if 'ESMFMKFILE' not in os.environ:
os.environ['ESMFMKFILE'] = str(Path(os.__file__).parent.parent / 'esmf.mk')
import xesmf Where we have to make assumptions about the file structure, but this would usually work in a conda env. This snippet goes at the top of your notebook. |
Hi @aulemahal, thanks a lot for the help! The trick of setting the environment variable in the jupyter notebook worked with Python 3.11! 🎉 It was really weird that the environment used in the terminal and in the jupyter notebook did something else, no idea, I'm too illiterate concerning environments on the cluster I'm working on unfortunately 😞 Actually, I alternatively also got it to work via the downgrading esmpy solution, I probably did something stupid before. Downgrading esmpy with Python 3.11 won't work despite several conda solving environment intents. With Python 3.10 it took conda also several solving environment intents for almost an hour, but finally it found a way to downgrade esmpy. |
I know this is very similar to an old issue that was previously reported (#246), sorry for reopening it, but I am not able to fix it despite several hours of trying and googling.
For the installation of xesmf, I followed the instructions and created a new environment.
When I try to import xesmf (in a jupyter notebook), I get the following error.
Downgrading esmf does not work with my newly created environment as mentioned in the issue, and the problem is also not solved by deactivating/reactivating the environment.
Curiously, I do not get the error when I try to import xesmf via the python console in the terminal.
My Python version is 3.11, but I've also tried with other versions and this also didn't work.
I know this could be something with my python installation on the cluster, but I've checked the usual hacks for using the same python version in jupyter notebook and python console, and they didn't help.
Any help is appreciated. xESMF is such a useful package, I just don't want a miss it in my jupyter notebooks. Thanks!
The text was updated successfully, but these errors were encountered: