pyGMT doesn't run on Pycharm but Jupyter

Hello everyone,

I’m not very familiar with Python, only used it sporadically with obspy. Recently in one of my master’s courses we learned about GMT and did a map on a chosen area, we used the non-python version of GMT. It wasn’t until now that I found out about pyGMT and therefore wanted to test it since I’m now more familiar with Python. Unfortunately I can’t get it to run on Pycharm, although I followed all instructions. I always get the error that pygmt modul is not found, but when I list all modules, it’s there…and I activated the environment.
Furthermore, I never used Jupyter before, just tested it and started it from Pycharm and pygmt works there…
Is there something I’m missing to get it to run on Pycharm?

Best wishes,
Henning

Hi @zersorger, welcome to the community! Could you copy and paste the error message you are getting (or a screenshot) so we can help debug this? You’ve probably had a search for other related issues already, but just in case:

It’s strange that PyGMT works in Jupyter for you but not in PyCharm. I realize that @Asril had the same problem at Complete question_Error_basemap plotting and may be able to help too. If possible, double check that you activated the ‘pygmt’ conda environment properly (try https://www.jetbrains.com/help/pycharm/conda-support-creating-conda-virtual-environment.html perhaps?) and report back.

Thanks very much @weiji14.

I dind’t change anything but deinstalled and reinstalled pygmt and restarted. But seems like overnight it started working (although I also de- and reinstalled it several times before…)!

1 Like

Great, glad to hear you solved it!

If you have some spare time, could you share the steps you did or some screenshots of how you set up PyCharm with PyGMT? It might be helpful to someone else using PyCharm in the future to know what settings to change in order for the code to run properly.

Hello
I am having similar problems: not able to make pyGMT work on PyCharm. I see you were missing some screenshots last time, so I am going to provide it:) I am not an expert with Python or Pycharm, so excuse trivialities…

  1. installing, following help (Path variables | PyCharm Documentation):
    Press Ctrl+Alt+S to open the IDE settings and then select Appearance & Behavior | Path Variables.

  1. successfully installed:

  2. pygmt.exceptions.GMTCLibNotFoundError: Error loading GMT shared library at ‘libgmt.so’.
    libgmt.so: cannot open shared object file: No such file or directory

I see its a pretty old conversation…but maybe still someone can help me (or others;) with it. Thanks Eva

Hi Eva,

Thanks for posting the screenshots :wink: The GMTCLibNotFoundError: Error loading GMT shared library at ‘libgmt.so’ you’re getting is likely because you have not installed the GMT C library (which is what PyGMT is wrapping around). I’d recommend you follow https://www.jetbrains.com/help/pycharm/conda-support-creating-conda-virtual-environment.html to set up a conda environment instead of a standard virtualenv (venv) if possible.