No module named pygmt in Spyder

Hello! I’m new to both python and gmt. I installed pygmt with anaconda following all instructions but when I try to import pygmt I get an error “no module named pygmt” … During the installation everything went fine, can anyone help me with this issue? Thank you.

Hi @Saren, welcome! Could you run us through the commands you used to arrive at the error? It might be that you need to do conda activate pygmt (or the name of your conda environment) first. If you copy and paste the full error mesage, or show us a screenshot of what’s happening, that will help us to help you better!

Hi! Thanks for your quick answer! I attached a screenshot of the error. I’m using spyder and I realised it was using pythong 3.7 instead of python 3.8, so I tried to import gmt in jupyter but the error is the same as you can see in the other picture . I tried a solution from github dated 2017 and it still doesn’t work… I installed anaconda two months ago,I updated it and tried to install gmt again but it still doesn’t work…

Ok, in Spyder on your bottom right, notice the “conda: base (Python 3.7.6)”? I’m not sure if you can click on it, but you’ll probably need to find a way to change it to “conda: pygmt (Python 3.8.X)”. This will make sure you’re using the 'pygmt' conda environment instead of the regular 'base' one.

In Jupyter notebook, you can click on Kernel-> Change Kernel -> pygmt to change the python kernel being used:

Note that I’m assuming you’ve followed the instructions at Installing — PyGMT to install gmt and pygmt into a python virtual environment called “pygmt” (Let me know if this is confusing). You could also type conda env list in the terminal to see if that’s the name you used.

Also, just a heads up that running pygmt.test() might give you some errors (see, don’t worry, that’s expected for now. Let me know if that helps :smile:

Thank you so much, you were right I wasn’t in the right environment: it turns out that to change environment with spyder you need to launch it from the anaconda prompt windows otherwise it can’t connect to the gmt kernel. Problem solved :sweat_smile:! Thank you again for your time :wink:

1 Like