Weird Jupyter vs. command prompt ModuleNotFoundError

Hello,
I followed the steps described on Installing — PyGMT and everything looked right. However, using the prompt I can start python and check pygmt.show_versions() BUT not in jupyter notebook or jupyter lab (see pictures).
On the kernel selection, only Python 3 is available.
Python and Pygmt is correctly installed and “pip install” shows “pygmt 0.3.1”.
What I’m doing wrong ?
image


You might need to install the pygmt kernel, see No module named pygmt - VS code, i.e. run this in your command prompt:

conda activate pygmt
python -m ipykernel install --user --name pygmt  #to install conda env properly
jupyter kernelspec list --json                   #see if kernel is installed

after that, you may need to shutdown jupyter and relaunch it to see the ‘pygmt’ kernel. Let us know if that works.

Voilà ! (Thanks @weiji14)
it worked like a charm, but I had to install the ipykernel. Interestingly I already had it in the base but when I installed pygmt via “conda create --name pygmt --channel conda-forge pygmt”, it just didn’t come with the ipykernel.

So, to recap: [from pygmt install instructions]

  1. conda config --prepend channels conda-forge
  2. conda create --name pygmt python=3.9 numpy pandas xarray netcdf4 packaging gmt
  3. conda activate pygmt
    [then]
  4. conda install pygmt
  5. [if you are paranoic] conda update pygmt
  6. [in my case] conda install ipykernel
  7. python -m ipykernel install --user --name pygmt
  8. jupyter kernelspec list --json [just to test…it worked]

2 Likes