Dumb question. I have a script that uses some matplotlib functions, but it cannot find these on cheyenne. Does anyone know what the issue with these lines would be:
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
from mpl_toolkits.axes_grid1 import make_axes_locatable
Note that I tried both the ncar_pylib and the conda environment.
@David Bailey: When you say "on cheyenne," do you mean that you are running on the JupyterHub on Cheyenne? Or is this in a python script that you are running on a Cheyenne login or compute node directly?
I am running a python script on a cheyenne node directly.
Ok. Thanks! How are you setting up your python environment? (e.g., is it a module load npl
or module load conda
etc.)
I did the module load conda and then conda activate npl.
:+1:
Ok. After conda activate npl
, can you do a conda list
? What does it show?
matplotlib 3.5.1 py37h89c1867_0 conda-forge
matplotlib-base 3.5.1 py37h1058ff1_0 conda-forge
matplotlib-inline 0.1.3 pyhd8ed1ab_0 conda-forge
No mpl_toolkits.
what about basemap?
No basemap either.
I'm not sure basemap is supported any more. The canonical replacement for basemap is cartopy. Is that the only "import error" that you are getting (namely, mpl_toolkit
)?
Yes, that is the one that is missing. When you say "not supported" can I still use it? The script is not that old.
I think you can still use it. But the NPL conda environment is supported by the CISL CSG folks, and you would need to ask them to install basemap in the NPL conda environment.
Got it. I suppose I could convert to cartopy. Can you point me to a good quick start guide?
Ryan Abernathey at LDEO has a nice tutorial on cartopy here:
https://rabernat.github.io/research_computing_2018/maps-with-cartopy.html
And he even mentions at the top that Basemap is "going away."
Great. I was able to do pip install basemap and get it working. So, that at least gives me a solution short-term.
Previous maintainers of basemap had indeed stepped away and pointed people to Cartopy, intending for a "final" release in 2020 with Python 2 EOL. I just now discovered that partial maintenance has been resumed by volunteers, and they seem to have chosen to remove said notices about deprecation and cut multiple new releases for Windows/Linux in just the past few months. I guess there's still some love for basemap!
Never underestimate open source, I guess! :smile: Thanks for that find, @Drew Camron!
Last updated: May 16 2025 at 17:14 UTC