lac at openend.se
Wed Sep 2 20:42:11 CEST 2015
>import numpy as np
>f = netCDF4.Dataset('uwnd.mon.ltm.nc','r')
>and I had the message:
>Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
>NameError: name 'netcdf4' is not defined
You have a file called netcdf4.py
It contains the line:
python comes along, reads
and goes looking for something named netCDF4 or netCdf4 or netcdf4
or NETDCF4 or NeTcDf4 -- the rules of your file system say that
filenames are case-insensitive ... so all the above are equivalent.
The first place it looks is your home directory. Then it looks in
your PYTHONPATH. Then it looks in the system modules you nicely
loaded for it.
Unfortunately for you, it finds the file netcdf4.py in your home
directory and thinks that is the one you wanted to import.
Solution -- stop naming your python files as lower-cased versions
of things you want to import. Renaming it to mynetcdf4.py should
work fine, for instance.
More information about the Python-list