NCAS-CMS / cf-python

A CF-compliant Earth Science data analysis library
http://ncas-cms.github.io/cf-python
MIT License
120 stars 19 forks source link

No module named 'netCDF4._netCDF4' #800

Closed JonathanGregory closed 1 month ago

JonathanGregory commented 1 month ago

This is very likely not a bug in cf-python but a problem with my software environment, which I don't understand. I can't import cf-python at the moment:

>>> import cf
Traceback (most recent call last):
  File "/home/users/sws02jmg/.local/lib/python3.9/site-packages/cfdm/core/__init__.py", line 29, in <module>
    import netCDF4
  File "/home/users/sws02jmg/.local/lib/python3.9/site-packages/netCDF4/__init__.py", line 3, in <module>
    from ._netCDF4 import *
ModuleNotFoundError: No module named 'netCDF4._netCDF4'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/users/sws02jmg/.local/lib/python3.9/site-packages/cf/__init__.py", line 96, in <module>
    import cfdm
  File "/home/users/sws02jmg/.local/lib/python3.9/site-packages/cfdm/__init__.py", line 44, in <module>
    from . import core
  File "/home/users/sws02jmg/.local/lib/python3.9/site-packages/cfdm/core/__init__.py", line 31, in <module>
    raise ImportError(_error0 + str(error1))
ImportError: cfdm.core requires the modules numpy, netCDF4, packaging. No module named 'netCDF4._netCDF4'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/users/sws02jmg/.local/lib/python3.9/site-packages/cf/__init__.py", line 98, in <module>
    raise ImportError(_error0 + str(error1))
ImportError: cf v3.16.1 requires the modules numpy, netCDF4, cftime, cfunits, cfdm, psutil, dask, packaging, scipy. cfdm.core requires the modules numpy, netCDF4, packaging. No module named 'netCDF4._netCDF4'

To see if I have the right packages, I did pip install -U cf-python, which concluded Successfully installed cf-python-3.16.2 cfunits-3.3.7 netCDF4-1.7.1.post1.

On the other hand, pip list reports that it has cf-python 3.16.1 and netCDF4 1.6.4. I don't understand how these can be different, or whether it's relevant.

This is on RACC, as you might guess. Any advice most welcome. Thanks.

davidhassell commented 1 month ago

Hi Jonathan - try downgrading netCDF4 to 1.6.5 (I'm on leave today, so that's all you'll get from me till next week :))

JonathanGregory commented 1 month ago

Thanks for the suggestion, @davidhassell. I have fixed it. I discovered that I had /home/users/sws02jmg/.local/lib/python3.9/site-packages in $PYTHONPATH instead of /home/users/sws02jmg/.local/lib/python3.11/site-packages. That also explains why the report from pip list did not make sense.