Skip to content
Advertisement

How to install NetCDF4 module in Spyder?

I don’t know why this is causing me so much headache.

I know how to use pip, and have the latest version, but still when running a script in Spyder that requires netCDF4 (import netCDF4) Spyder always returns:

import netCDF4
ModuleNotFoundError: No module named 'netCDF4'"
  1. I opened cmd, pip install netCDF4, confirmed it installed OK. Shouldn’t this be enough?
  2. I manually copied a downloaded version of netCDF4, moved it to my Python site packages, and then in Spyder manually went into PYTHONPath Manager -> Add Path –> Added the folder location ‘netCDF4-1.6.0’. I thought this would definitely be enough?
  3. Then INSIDE Spyder’s python console, bot-right of screen, I tried ‘pip install netCDF4’ and it returns:
Note: you may need to restart the kernel to use updated packages.
C:...SpyderPythonpython.exe: No module named pip

So is my issue #3? Spyder’s version of Python doesn’t have pip and doesn’t link to the netCDF4 module? I thought my step #2 would resolve this?

Any help on how to install modules in Spyder would be appreciated, thank you!

Advertisement

Answer

Download Miniconda and install all the packages you want in a new environment. For example,

conda create -n myenv -c conda-forge python=3.9 netcdf4 [others ...]

Then follow the Spyder documentation for adding a conda environment.

Credit to Michael Delgado (above)

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement