Complete question_Error_basemap plotting

Hello Leo

I am learning GMT plotting and getting across with your github about pygmt. I am also learning python.

I use Pycharm IDE and was trying to plot the basemap of your poster titled Central america with exact code written on your poster. Unfortunately, it does not work. I installed pygmt for the project interpreter.

I tried to rewrite your script of basemap plotting on my pycharm. The script is such below

import pygmt
fig = pygmt.Figure()
fig.basemap(region=[-100, -50, 5, 25], frame=True, projection="M20c")
fig.coast(shorelines=True)
fig.savefig("central-america.png")
fig.show()

But the result is getting error. The comment is below

"C:\Users\HP OMEN\AppData\Local\Programs\Python\Python37-32\python.exe" "C:/Users/HP OMEN/Python Practices/basemap.py"
Traceback (most recent call last):
  File "C:/Users/HP OMEN/Python Practices/basemap.py", line 1, in <module>
    import pygmt
  File "C:\Users\HP OMEN\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pygmt\__init__.py", line 31, in <module>
    _begin()
  File "C:\Users\HP OMEN\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pygmt\session_management.py", line 16, in begin
    with Session() as lib:
  File "C:\Users\HP OMEN\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pygmt\clib\session.py", line 177, in __enter__
    self.create("pygmt-session")
  File "C:\Users\HP OMEN\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pygmt\clib\session.py", line 328, in create
    restype=ctp.c_void_p,
  File "C:\Users\HP OMEN\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pygmt\clib\session.py", line 276, in get_libgmt_func
    self._libgmt = load_libgmt()
  File "C:\Users\HP OMEN\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pygmt\clib\loading.py", line 48, in load_libgmt
    ", ".join(lib_fullnames)
pygmt.exceptions.GMTCLibNotFoundError: Error loading the GMT shared library 'gmt.dll, gmt_w64.dll, gmt_w32.dll, c:\programs\gmt6\bin\gmt_w64.dll':

Process finished with exit code 1

Could you guide me to solve it? Thanks in advance

Hi Asril,

Thr error seems to indicate that you installed PyGMT, but not GMT. Maybe try following the instructions at https://www.pygmt.org/latest/install.html#installing-gmt-and-other-dependencies and see if it helps. Or have a look at No module named pygmt (also from someone using PyCharm).

There is no GMT module available in the PyCharm, but there is only pygmt. Should I install other IDEs to have GMT module?

No, you just need to install GMT which is a C library (i.e. non-python). PyGMT is a Pythonic wrapper around this GMT C library.

Do you mean such this installed GMT?

Thanks

If you use anaconda simply create a new environment by:

conda create --name pygmt python=3.8 pip numpy pandas xarray netcdf4 packaging gmt

which will install GMT. Then follow the instructions given by @weiji14

Thank mgrund. That means I have to install anaconda for running the package

I don’t understand why the recommendation is to install Anaconda (a multi Giga bytes beast) and its GMT. I have the official GMT binaries (Windows) and PyGMT works for me. Never tried from an IDE though.

1 Like

Try Miniconda, it’s only ~55MB. Anaconda is meant for people who just want everything. Using conda is the recommended method for PyGMT as you don’t have to mess with the $PATH variables.

Or you can go with @Joaquim’s suggestion and download GMT at https://www.generic-mapping-tools.org/download/, and set the $GMT_LIBRARY_PATH following https://www.pygmt.org/dev/install.html#finding-the-gmt-shared-library.

I’m yet to see a such small Conda. Mine has 6.7 GB (???) and recently on Julia for a package that needed netcdf.dll it installed a conda with ~800 MB.

I also don’t understand why one needs to set GMT_LIBRARY_PATH on Windows (we don’t). With a correct GMT installation the GMT bin dir is in the Windows path so the system knows how to find there the gmt dll.

BTW, on Julia I make use of the fact that gmt --show-library tells us where is the GMT shared lib. I use it on *nix to find the lib. I think the same could be adopted by pygmt and hence no more need for a how-to-find-the-gmt-shared-library

good point! @weiji14 ’ s suggestion to use miniconda here is obviously the better way instead installing the whole anaconda content. Miniconda should be less than 100 MB, regardless which OS (https://docs.conda.io/en/latest/miniconda.html).

Mine is a miniConda to which I added some packages over the time. But I still think is preferable to install 0 Mb extras when that is possible. A GMT-in-conda is not easily used outside python so often users will end up with two GMT installations.

Yes or you use miniconda if you dont need all the rest which comes along with anaconda as suggested by @weiji14 . However @Joaquim lined out a way how you can do it without having anaconda/miniconda.

Thank for your @weiji14, @Joaquim ,and @mgrund suggestions. Before receiving these messages, I installed the Anaconda and tried to run the same script runned in the Pycharm. Then the same result appeared (as picture) that @Saren experienced and solved. I tried to do what @weiji14 suggested for @Saren that changed from conda : base to kernel. The conda:base can not be clicked on. Could you @weiji14 or @Saren help me how to do that. Many thanks