PyGMT-Error with saveFig(), show() because of psconvert

Hi there,

I am trying to run a basic python program after installing pyGMT. It has been a rough journey as install is very cumbersome and lots of issues with missing libraries and need for manually identifying location of libraries. The problem do not stop there.

I am running following code and am getting error message. Can somebody help in this regards? Thanks in advance.

import os
os.system('GMT_LIBRARY_PATH=/opt/conda/envs/pygmt/lib')
import pygmt

fig = pygmt.Figure()
fig.basemap(region=["-90.00", "-70.00", "0.00", "20.00"], projection="M8i", frame=True)
fig.coast(shorelines=True)
fig.show()
fig.savefig('123.png')

I also tried using regions as [-90,-70,0,20] and error is still there.

Error Message:

psconvert [ERROR]: Cannot execute Ghostscript (gs).
Traceback (most recent call last):  File "pygmtTest.py", line 8, in <module>
    fig.show()
  File "/opt/conda/lib/python3.8/site-packages/pygmt/figure.py", line 280, in show
    png = self._preview(  File "/opt/conda/lib/python3.8/site-packages/pygmt/figure.py", line 353, in _preview
    self.savefig(fname, dpi=dpi, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/pygmt/figure.py", line 234, in savefig
    self.psconvert(prefix=prefix, fmt=fmt, crop=crop, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/pygmt/helpers/decorators.py", line 270, in new_module
    return module_func(*args, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/pygmt/helpers/decorators.py", line 411, in new_module
    return module_func(*args, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/pygmt/figure.py", line 174, in psconvert
    lib.call_module("psconvert", build_arg_string(kwargs))
  File "/opt/conda/lib/python3.8/site-packages/pygmt/clib/session.py", line 506, in call_module
    raise GMTCLibError(
pygmt.exceptions.GMTCLibError: Module 'psconvert' failed with status code 78:
psconvert [ERROR]: Cannot execute Ghostscript (gs).

SA

Not a Python user so cannot advice on the libraries, but since GMT calls gs via a system call, the ghostscript executable needs to be in your PATH.

Thanks for your reply. I am a new user too so can you guide me how to check for PATH and to make sure I do have executable in my PATH.

What I am trying to do is to plot a map overlaid with GPS location on left hand and then plotting data from a particular station for xyz values on right hand side?

I have some code in python and GMT portion is in shell script so I was trying to figure to integrate both of them.

Can you guide me in this regards?

Appreciate for your help.

SA

Hopefully, @seisman can provide more specific help on the PyGMT side. Did you install gs? It is a run-time prerequisite for GMT. In your shell, if you type which gs, does it return the path to the gs app?

Hi @sarya, thanks for trying PyGMT out! Just to double check, are you running this as a script or or an IDE (e.g. Jupyter)? Could you also post the output of pygmt.show_versions() so we can debug further. If you’re using conda, did you do conda activate pygmt first? My guess as Paul mentioned is something about your PATH, which you can check using env | grep PATH on the terminal.

Thanks a bunch for your quick reply. Let me clarify what i am working on so you can guide me towards right approach. I am newbie and and am piecemealing to reach my solution.

I have station data xyz month records as tar.gz file which has bunch of daily record text files as txt.gz. I have to plot location map of that area and then over lay stations in that area and then on another side I have to plot x,y,z data.

Approach I have taken so far is:

  1. Using bash commands I am combining files and converting into temporary plain text file.
  2. Using GMT in shell I am creating map with overlaid station data from another stations location csv file and saving final plot as PNG file.
  3. Using python matplotlib I am plotting three charts and saving them as PNG.
  4. Finally I am stitching two PNGS files above using Python Image library to create one.

Because this is so crooked way of doing things, I was thinking of using pyGMT and do it all in python. But problem is different library locations.

First when I installed pyGMT as per instructions I was getting error messages at import pygmt and was missing reference to library.
“pygmt.exceptions.GMTCLibNotFoundError: Error loading the GMT shared library ‘libgmt.so’”

So my solution for that was:

import os
os.system(‘GMT_LIBRARY_PATH=/opt/conda/envs/pygmt/lib’)
import pygmt

and it worked. Now when I am running rest of my code.

pygmt.Figure()
fig.basemap(region=[“-90.00”, “-70.00”, “0.00”, “20.00”], projection=“M8i”, frame=True)
fig.coast(shorelines=True)
fig.show()
fig.savefig(“123.png”)

I started getting error message. “psconvert [ERROR]: Cannot execute Ghostscript (gs)”.

Sorry this was lot of background.

To answer your specific questions:

  1. which gs → /opt/conda/envs/pag_gmt/bin/gs . Now this is in different environment pag_gmt from one that changed in my code to run pygmt :slight_smile:import os

os.system(‘GMT_LIBRARY_PATH=/opt/conda/envs/pygmt/lib’)
import pygmt

How to get both in same environment or location?

  1. I am using Jupyter.

  2. pygmt.show_version() output
    (base) jovyan@jupyter-sarya:~/Project$ python3 pygmtTest.py
    PyGMT information:
    version: v0.2.1
    System information:
    python: 3.8.6 | packaged by conda-forge | (default, Oct 7 2020, 19:08:05) [GCC 7.5.0]
    executable: /opt/conda/bin/python3
    machine: Linux-4.14.203-156.332.amzn2.x86_64-x86_64-with-glibc2.10
    Dependency information:
    numpy: 1.19.2
    pandas: 1.1.3
    xarray: 0.16.2
    netCDF4: 1.5.4
    packaging: 20.4
    ghostscript: None
    gmt: None
    GMT library information:
    binary dir: /opt/conda/bin
    cores: 8
    grid layout: rows
    library path: /opt/conda/envs/pygmt/lib/libgmt.so
    padding: 2
    plugin dir: /opt/conda/envs/pygmt/lib/gmt/plugins
    share dir: /opt/conda/envs/pygmt/share/gmt
    version: 6.1.1

  3. env | grep PATH output

(base) jovyan@jupyter-sarya:~/Project$ env | grep PATH
GMT_LIBRARY_PATH=/opt/conda/envs/pygmt/lib
PYTHONPATH=:/opt/isce2:/usr/local/TRAIN/src:/usr/local/MintPy:/usr/local/PyAPS
PATH=/opt/conda/bin:/opt/conda/bin:/opt/conda/condabin:/opt/conda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/isce2/isce/bin:/opt/isce2/isce/applications:/usr/local/mapready/bin:/usr/local/mapready/lib:/usr/local/mapready/share:/usr/lib/jvm/java-11-openjdk-amd64/bin:/usr/local/MintPy/mintpy:/usr/local/MintPy/sh

I do think problem may be with different environment. Any suggestions on better way to do this.

Thanks.

SA

It seems you’re NOT switching to the pygmt environment, so all dependencies (e.g., GMT, and gs) can’t be found.

Hi,

When I set “conda activate pygmt” and then run the code I get error at import pygmt.

(base) jovyan@jupyter-sarya:~/Project$ conda activate pygmt

(pygmt) jovyan@jupyter-sarya:~/Project$ python3 pygmtTest.py
Traceback (most recent call last):
File “pygmtTest.py”, line 3, in
import pygmt
ModuleNotFoundError: No module named ‘pygmt’

Code is same as above.

Did you activate your pygmt environment when you installed pygmt via conda install pygmt? If not, I’m afraid pygmt was installed in your base environment, and now you need to run conda install pygmt to install it in the pygmt environment again.

Many many thanks to all of you @seisman @pwessel and weiji14. Your input greatly helped a newbie. Thanks a bunch.

Hello @seisman and others - newbie here.

I was use to use GMT and when I discovered that there is a pyGMT I was all in. But I have similar issue as Sarya. I was running the first ‘hello world’ script and it fails to save the fig due to psconvert.

GMTCLibError : Module ‘psconvert’ failed with status code 78: psconvert [ERROR]: System call :[@gswin64c -q -dNOPAUSE -dBATCH -dNOSAFER -dSCANCONVERTERTYPE=2 -dMaxBitmap=2147483647 -dUseFastColor=true -dGraphicsAlphaBits=2 -dTextAlphaBits=2 -sDEVICE=png16m -g2631x2592 -r300 -sOutputFile=“central-america-shorelines.png” “C:/Users/nobody/.gmt/sessions/gmt_session.24580/psconvert_25576d.eps”] returned error 1.

I am runnning it in Visual Code on W10. Other information is here:

PyGMT information:
version: v0.3.0
System information:
python: 3.9.2 | packaged by conda-forge | (default, Feb 21 2021, 04:59:43) [MSC v.1916 64 bit (AMD64)]
executable: c:\Users\nobody\anaconda3\envs\pygmt\pythonw.exe
machine: Windows-10-10.0.18362-SP0
Dependency information:
numpy: 1.20.1
pandas: 1.2.3
xarray: 0.17.0
netCDF4: 1.5.6
packaging: 20.9
ghostscript: 9.53.3
gmt: 6.1.1
GMT library information:
binary dir: c:/Users/nobody/anaconda3/envs/pygmt
cores: 6
grid layout: rows
library path: C:/Users/nobody/anaconda3/envs/pygmt/Library/bin/gmt.dll
padding: 2
plugin dir: C:/Users/nobody/anaconda3/envs/pygmt/Library/bin/gmt_plugins
share dir: c:/programs/gmt6/share
version: 6.1.1

Hopefully I wrote it well and you can somehow help me :). My first time asking for some specific help.

Hi @scavatore, thanks for trying out PyGMT! Your psconvert error looks exactly the same as what I had reported in https://github.com/GenericMappingTools/pygmt/issues/829. Unfortunately, I was unable to reproduce it and solve it, but looks like we’ll need to help you out here!

To double check, could you try and run the following GMT command in your command-line (after conda activate pygmt) and see if it produces the same error:

gmt basemap -R0/1/0/1 -JX1 -Baf -Vi -png map

That way we’ll know whether it’s a problem on the PyGMT or GMT conda package.

Hi @weiji14, thank you for the fast answer.
GMT command runs fine, without error.
I looked in that issue you mentioned and followed the steps, I don’t have gswin64c in this path: c:/Users/username/.conda/envs/pygmt/Library/bin/gswin64c.exe
but in slightly different:
C:/Users/username/anaconda3/envs/pygmt/Library/bin/gswin64c.exe
but I am not sure if that is the problem, probably not.

Cool, then it should be something on the Python/PyGMT side that is the issue then.

The difference in path (‘.conda’ vs ‘anaconda3’) shouldn’t matter, just depends on the way Anaconda was installed.

The thread at Error with psconvert finding gswin64 · Issue #829 · GenericMappingTools/pygmt · GitHub also suggests to install Ghostscript using the official installer (at Ghostscript : Downloads), which updates the Windows registry. I didn’t manage to do this on my university computer because I didn’t have administrative permissions, but I know a friend who managed to do this successfully by copying that installed gswin64c.exe file to the path PyGMT was calling ghostscript (or something like that). Ping @seisman for other ideas on how to troubleshoot.

grid layout: rows
library path: C:/Users/nobody/anaconda3/envs/pygmt/Library/bin/gmt.dll
padding: 2
plugin dir: C:/Users/nobody/anaconda3/envs/pygmt/Library/bin/gmt_plugins
share dir: c:/programs/gmt6/share
version: 6.1.1

The output seems weird. It shows that PyGMT is loading the gmt.dll DLL library from conda-forge, but the share dir is c:/programs/gmt6/share. I think it means you have two GMT versions installed. One is from the official GMT installer (installed at C:/programs/gmt6), another one is from conda-forge (installed at C:/Users/nobody/anaconda3/envs/pygmt/Library/bin/). It also means you may have two ghostscript installed. But I’m not sure how two versions of ghostscript or GMT can cause the problem you have.

Could you try this:

  1. Similar to what @weiji14 suggested, run run the following GMT command in your command-line (after conda activate pygmt ), and post the full output.
gmt basemap -R0/1/0/1 -JX5c -Baf -Vd -png map
  1. Run the following python script, and post the output:
import pygmt
fig = pygmt.Figure()
fig.basemap(region=[0, 1, 0, 1], projection="X5c", frame="af")
fig.savefig("map.png", V='d')

Hi, thank you for caring @seisman. Yes I installed gmt and gs before the pygmt. I discovered pygmt last week but I am using gmt for years, mainly on Linux at uni but also on Windows on my computer.

So:

  1. I activated pygmt and ran that command output is following:
gmt [DEBUG]: Obtained the ppid from parent: 4312
gmt [DEBUG]: Enter: gmtinit_new_GMT_ctrl
gmt [DEBUG]: GMT->session.SHAREDIR = C:/programs/gmt6/share
gmt [DEBUG]: GMT->session.HOMEDIR = C:/Users/nobody
gmt [DEBUG]: GMT->session.USERDIR = C:/Users/nobody/.gmt [created]
gmt [DEBUG]: GMT->session.CACHEDIR = C:/Users/nobody/.gmt/cache [created]
gmt [DEBUG]: GMT: 0. Will try to find subdir=postscriptlight stem = PSL_custom_fonts suffix=.txt
gmt [DEBUG]: GMT: 1. gmt_getsharepath trying current dir
gmt [DEBUG]: GMT: 2. gmt_getsharepath trying USERDIR C:/Users/nobody/.gmt
gmt [DEBUG]: GMT: 3. gmt_getsharepath trying USERDIR subdir C:/Users/nobody/.gmt/postscriptlight
gmt [DEBUG]: GMT: 4. gmt_getsharepath trying SHAREDIR subdir C:/programs/gmt6/share/postscriptlight
gmt [DEBUG]: GMT: 5. gmt_getsharepath trying SHAREDIR C:/programs/gmt6/share
gmt [DEBUG]: GMT: 6. gmt_getsharepath failed
gmt [DEBUG]: Map distance calculation will be Cartesian
gmt [DEBUG]: Exit:  gmtinit_new_GMT_ctrl
gmt [DEBUG]: Enter: New_PSL_Ctrl
gmt [DEBUG]: Exit:  New_PSL_Ctrl
gmt [DEBUG]: Enter: gmt_manage_workflow
gmt [DEBUG]: Exit : gmt_manage_workflow
gmt [DEBUG]: Enter: PSL_beginsession
gmt [DEBUG]: Exit : PSL_beginsession
gmt [DEBUG]: Enter: PSL_setdefaults
gmt [DEBUG]: Exit : PSL_setdefaults
gmt [DEBUG]: Enter: gmtlib_io_init
gmt [DEBUG]: Exit : gmtlib_io_init
gmt [DEBUG]: Enter: gmt_hash_init
gmt [DEBUG]: Exit:  gmt_hash_init
gmt [DEBUG]: Enter: gmt_hash_init
gmt [DEBUG]: Exit:  gmt_hash_init
gmt [DEBUG]: Enter: gmt_reload_settings
gmt [DEBUG]: The PROJ_GEODESIC set to Vincenty
gmt [DEBUG]: Look for file C:/Users/nobody/gmt.conf
gmt [DEBUG]: Look for file C:/Users/nobody/.gmt/gmt.conf
gmt [DEBUG]: Look for file C:/Users/nobody/.gmt/server/gmt.conf
gmt [DEBUG]: Look for file C:/Users/nobody/.gmt/cache/gmt.conf
gmt [DEBUG]: Could not find file gmt.conf
gmt [DEBUG]: Exit:  gmt_reload_settings
gmt [DEBUG]: Enter: gmtlib_plot_C_format
gmt [DEBUG]: Exit:  gmtlib_plot_C_format
gmt [DEBUG]: Enter: gmtinit_get_history
gmt [DEBUG]: Initialize FFTW with 6 threads.
gmt [DEBUG]: GMT_Create_Session initialized GMT structure
gmt [DEBUG]: Loading core GMT shared library: gmt.dll
gmt [DEBUG]: Shared Library # 0 (core). Path = gmt.dll
gmt [DEBUG]: Loading GMT plugins from: C:/Users/nobody/anaconda3/envs/pygmt/Library/bin/gmt_plugins
gmt [DEBUG]: Shared Library # 1 (supplements). Path = C:/Users/nobody/anaconda3/envs/pygmt/Library/bin/gmt_plugins/supplements.dll
gmt [DEBUG]: Revised options: map png
begin [INFORMATION]: Creating a workflow directory C:/Users/nobody/.gmt/sessions/gmt_session.4312
begin [DEBUG]: The PROJ_GEODESIC set to Vincenty
begin [DEBUG]: Look for file C:/Users/nobody/gmt.conf
begin [DEBUG]: Look for file C:/Users/nobody/.gmt/gmt.conf
begin [DEBUG]: Look for file C:/Users/nobody/.gmt/server/gmt.conf
begin [DEBUG]: Look for file C:/Users/nobody/.gmt/cache/gmt.conf
begin [DEBUG]: Could not find file gmt.conf
begin [DEBUG]: Set session name to be map png
begin [DEBUG]: Begin Workflow.  Session ID = 4312. Directory C:/Users/nobody/.gmt/sessions/gmt_session.4312 created.
begin [DEBUG]: GMT now running in modern mode [Session ID = 4312]
gmt [DEBUG]: Use PS filename C:/Users/nobody/.gmt/sessions/gmt_session.4312/gmt_0.ps-
gmt [DEBUG]: gmtinit_get_current_panel: No current panel selected so not in subplot mode
gmt [DEBUG]: Revised options: -R0/1/0/1 -JX5c -Baf -Vd
basemap [DEBUG]: History: Process -R0/1/0/1
basemap [DEBUG]: History: Process -JX5c
basemap [DEBUG]: gmt_get_filename: In: 0/1/0/1 Out: 0/1/0/1
basemap [DEBUG]: Look for file 0/1/0/1 in C:/Users/nobody/.gmt
basemap [DEBUG]: Look for file 0/1/0/1 in C:/Users/nobody/.gmt/cache
basemap [DEBUG]: Look for file 0/1/0/1 in C:/Users/nobody/.gmt/server
basemap [DEBUG]: Got regular w/e/s/n for region (0/1/0/1)
basemap [INFORMATION]: Constructing the basemap
basemap [DEBUG]: Projected values in meters: 0 1 0 1
basemap [DEBUG]: Auto-frame interval for axis 0 item 0: d = 0.2  f = 0.1
basemap [INFORMATION]: Auto-frame interval for x-axis (item 0): a0.2f0.1
basemap [DEBUG]: Auto-frame interval for axis 1 item 0: d = 0.2  f = 0.1
basemap [INFORMATION]: Auto-frame interval for y-axis (item 0): a0.2f0.1
basemap [INFORMATION]: Map scale is 0.0002 km per cm or 1:20.
basemap [DEBUG]: Running in PS mode modern
basemap [DEBUG]: Use PS filename C:/Users/nobody/.gmt/sessions/gmt_session.4312/gmt_0.ps-
basemap [DEBUG]: Create hidden PS file C:/Users/nobody/.gmt/sessions/gmt_session.4312/gmt_0.ps-
basemap [DEBUG]: No figure file C:/Users/nobody/.gmt/sessions/gmt_session.4312/gmt.figures - nothing to do
basemap [DEBUG]: Got session name as map and default graphics formats as png
basemap [DEBUG]: Current size of half-baked PS file C:/Users/nobody/.gmt/sessions/gmt_session.4312/gmt_0.ps- = 23027.
psbasemap (Free_Ctrl): tried to free unallocated memory
psbasemap (Free_Ctrl): tried to free unallocated memory
psbasemap (Free_Ctrl): tried to free unallocated memory
basemap [DEBUG]: GMT now running in modern mode [Session ID = 4312]
basemap [DEBUG]: Revised options: show
basemap (gmtlib_free_tmp_arrays): tried to free unallocated memory
end [DEBUG]: End Workflow.  Session ID = 4312. Directory C:/Users/nobody/.gmt/sessions/gmt_session.4312 removed.
end [DEBUG]: No figure file C:/Users/nobody/.gmt/sessions/gmt_session.4312/gmt.figures - nothing to do
end [DEBUG]: No figure file C:/Users/nobody/.gmt/sessions/gmt_session.4312/gmt.figures - nothing to do
end [DEBUG]: Got session name as map and default graphics formats as png
end [INFORMATION]: Process GMT figure queue: 1 figures found
end [INFORMATION]: Processing GMT figure #0 [map png ]
end [DEBUG]: gmtlib_get_graphics_item: Fig: 0 Subplot: 2 Panel: () Inset: 0
end [DEBUG]: psconvert: 'C:/Users/nobody/.gmt/sessions/gmt_session.4312/gmt_0.ps-' -Tg -Fmap -A
end [DEBUG]: GMT now running in modern mode [Session ID = 4312]
end [DEBUG]: Revised options: 'C:/Users/nobody/.gmt/sessions/gmt_session.4312/gmt_0.ps-' -Tg -Fmap -A
end (gmtlib_free_tmp_arrays): tried to free unallocated memory
psconvert [DEBUG]: gmt_check_executable: Pass to popen: ["C:/Users/nobody/anaconda3/envs/pygmt/Library/bin/gswin64c.exe" --version 2> NUL]
psconvert [DEBUG]: "C:/Users/nobody/anaconda3/envs/pygmt/Library/bin/gswin64c.exe" --version 2> NUL was successful
psconvert [DEBUG]: Ghostscript version: 9.53
psconvert [DEBUG]: Complete partial PS file C:/Users/nobody/.gmt/sessions/gmt_session.4312/gmt_0.ps-
psconvert [DEBUG]: Size of half-baked PS file = 23027.
psconvert [DEBUG]: Fattened up PS file C:/Users/nobody/.gmt/sessions/gmt_session.4312/gmt_0.ps-
psconvert [INFORMATION]: Processing C:/Users/nobody/.gmt/sessions/gmt_session.4312/gmt_0.ps-...
psconvert [INFORMATION]: Find HiResBoundingBox ...
psconvert [DEBUG]: Running: @"C:/Users/nobody/anaconda3/envs/pygmt/Library/bin/gswin64c.exe" -q -dNOSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox -DPSL_no_pagefill -dMaxBitmap=2147483647 -dUseFastColor=true "C:/Users/nobody/.gmt/sessions/gmt_session.4312/gmt_0.ps-" 2> "C:/Users/nobody/.gmt/sessions/gmt_session.4312/psconvert_17332c.bb"
psconvert [INFORMATION]: Figure dimensions: Width: 194.094 points [6.8472 cm]  Height: 179.244 points [6.32333 cm]
psconvert [DEBUG]: Delete C:/Users/nobody/.gmt/sessions/gmt_session.4312/psconvert_17332c.bb
psconvert [INFORMATION]: [333.846 341.118 527.94 520.362]...
psconvert [INFORMATION]: An unknown psconvert setting was found but since image coordinates seem to be geographical, a linear transformation will be used.
psconvert [INFORMATION]: Convert to PNG...
psconvert [DEBUG]: Running: @"C:/Users/nobody/anaconda3/envs/pygmt/Library/bin/gswin64c.exe" -q -dNOPAUSE -dBATCH -dNOSAFER -dSCANCONVERTERTYPE=2 -dMaxBitmap=2147483647 -dUseFastColor=true -dGraphicsAlphaBits=2 -dTextAlphaBits=4 -sDEVICE=png16m  -g809x747 -r300 -sOutputFile="map.png" "C:/Users/nobody/.gmt/sessions/gmt_session.4312/psconvert_17332d.eps"
psconvert [DEBUG]: Delete C:/Users/nobody/.gmt/sessions/gmt_session.4312/psconvert_17332d.eps
psconvert [DEBUG]: Final input buffer length was 128
psconvert (gmtlib_free_tmp_arrays): tried to free unallocated memory
end [DEBUG]: GMT now running in modern mode [Session ID = 4312]
end [DEBUG]: Revised options: map.png
end (gmtlib_free_tmp_arrays): tried to free unallocated memory
docs [DEBUG]: Opening local file map.png via cmd /c start
docs (gmtlib_free_tmp_arrays): tried to free unallocated memory
end [INFORMATION]: Destroying the current workflow directory C:/Users/nobody/.gmt/sessions/gmt_session.4312
end [DEBUG]: Delete gmt.canvas.0
end [DEBUG]: Delete gmt.conf
end [DEBUG]: Delete gmt.frame
end [DEBUG]: Delete gmt.layers.0
end [DEBUG]: Delete gmt.session
end [DEBUG]: Delete gmt_0.ps-
end (gmtlib_free_tmp_arrays): tried to free unallocated memory
psbasemap (gmtlib_free_tmp_arrays): tried to free unallocated memory
gmt [DEBUG]: Entering GMT_Destroy_Session
gmt [DEBUG]: gmtlib_get_graphics_item: Fig: 0 Subplot: 2 Panel: () Inset: 0
  1. Output from python script:
psconvert [DEBUG]: Ghostscript not found in registry. Fallback to PATH.
psconvert [DEBUG]: gmt_check_executable: Pass to popen: [gswin64c --version 2> NUL]
psconvert [DEBUG]: gswin64c --version 2> NUL was successful
psconvert [DEBUG]: Ghostscript version: 9.53
psconvert [DEBUG]: Use PS filename C:/Users/nobody/.gmt/sessions/gmt_session.4312/gmt_1.ps-
psconvert [DEBUG]: Hidden PS file C:/Users/nobody/.gmt/sessions/gmt_session.4312/gmt_1.ps- found
psconvert [DEBUG]: Complete partial PS file C:/Users/nobody/.gmt/sessions/gmt_session.4312/gmt_1.ps-
psconvert [DEBUG]: Size of half-baked PS file = 23023.
psconvert [DEBUG]: Fattened up PS file C:/Users/nobody/.gmt/sessions/gmt_session.4312/gmt_1.ps-
psconvert [INFORMATION]: Processing C:/Users/nobody/.gmt/sessions/gmt_session.4312/gmt_1.ps-...
psconvert [INFORMATION]: Find HiResBoundingBox ...
psconvert [DEBUG]: Running: @gswin64c -q -dNOSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox -DPSL_no_pagefill -dMaxBitmap=2147483647 -dUseFastColor=true "C:/Users/nobody/.gmt/sessions/gmt_session.4312/gmt_1.ps-" 2> "C:/Users/nobody/.gmt/sessions/gmt_session.4312/psconvert_14160c.bb"
psconvert [INFORMATION]: Figure dimensions: Width: 194.094 points [6.8472 cm]  Height: 179.244 points [6.32333 cm]
psconvert [DEBUG]: Delete C:/Users/nobody/.gmt/sessions/gmt_session.4312/psconvert_14160c.bb
psconvert [INFORMATION]: [333.846 341.118 527.94 520.362]...
psconvert [INFORMATION]: An unknown psconvert setting was found but since image coordinates seem to be geographical, a linear transformation will be used.
psconvert [INFORMATION]: Convert to PNG...
psconvert [DEBUG]: Running: @gswin64c -q -dNOPAUSE -dBATCH -dNOSAFER -dSCANCONVERTERTYPE=2 -dMaxBitmap=2147483647 -dUseFastColor=true -dGraphicsAlphaBits=2 -dTextAlphaBits=2 -sDEVICE=png16m  -g809x747 -r300 -sOutputFile="map.png" "C:/Users/nobody/.gmt/sessions/gmt_session.4312/psconvert_14160d.eps"
psconvert [DEBUG]: Delete C:/Users/nobody/.gmt/sessions/gmt_session.4312/psconvert_14160d.eps
psconvert [DEBUG]: Final input buffer length was 128
psconvert (gmtlib_free_tmp_arrays): tried to free unallocated memory

The map.png file was created. So it seems that your thoughts are correct. What is the solution?
Thank you!

I don’t see anything wrong in your verbose output. Everything looks good and the image is also produced. If you remove V='d' from the python script, do you still see the error?

Okay, now it’s fine. At least when I run the script in conda prompt. But if I run it in VSCode interactive window, there is still error with saving of the picture. But that is not related with pygmt but with something else I suppose. So I will use it just for testing and saving pictures will be done this normal way.
Thank you for all help.

Hi, I use jupyter notebook and I have the same error. I find the reason in my case is that I create a fig in one cell and then continue to decorate the same fig in a different cell. I solve the error by completing the fig in one cell and then save it using fig.savefig.

Hope it can help:>