Error in saving PyGMT figure

Hello all!
I have been using Pygmt since last year. I find no such major problems. But today, while I was saving my figures I got the following error:
GMTCLibError: Module ‘psconvert’ failed with status code 79:
psconvert [ERROR]: System call [@gswin64c -q -dNOPAUSE -dBATCH -dNOSAFER -dSCANCONVERTERTYPE=2 -dMaxBitmap=2147483647 -dUseFastColor=true -dGraphicsAlphaBits=2 -dTextAlphaBits=2 -sDEVICE=pngalpha -g2397x1195 -r300 -sOutputFile=“L:/PhD/Paper-2 SM Complex Network/ECA/figures/Correlation_E_T.png” “C:/Users/ktripat/.gmt/sessions/gmt_session.25792/psconvert_21416d.eps”] returned error 1.

In the anaconda command prompt, where I activated the pygmt environment using “conda activate pygmt”, its showing the error: “GPL Ghostscript 9.54.0: Unrecoverable error, exit code 1”.

I have given a picture of the error that I get in the jupyter notebook. Please look at it.

This error was not before today and I was able to smoothly save the figures. Can anyone tell me how to fix this bug???

Thank you
Regards
Kumar

Could you please post the output of the following codes?

import pygmt
pygmt.show_versions()

Hi @seisman thank you for replying back me.
I run your code in jupyter and this is the output I get:

PyGMT information:
version: v0.7.0
System information:
python: 3.10.5 | packaged by conda-forge | (main, Jun 14 2022, 06:57:19) [MSC v.1929 64 bit (AMD64)]
executable: C:\Users\ktripat\Anaconda3\envs\pygmt2\python.exe
machine: Windows-10-10.0.19044-SP0
Dependency information:
numpy: 1.23.1
pandas: 1.4.3
xarray: 2022.3.0
netCDF4: 1.6.0
packaging: 21.3
geopandas: None
ghostscript: 9.54.0
gmt: 6.4.0
GMT library information:
binary dir: C:/Users/ktripat/Anaconda3/envs/pygmt2
cores: 8
grid layout: rows
library path: C:/Users/ktripat/Anaconda3/envs/pygmt2/Library/bin/gmt.dll
padding: 2
plugin dir: C:/Users/ktripat/Anaconda3/envs/pygmt2/Library/bin/gmt_plugins
share dir: C:/Users/ktripat/Anaconda3/envs/pygmt2/Library/share/gmt
version: 6.4.0
I believe everything works perfectly, but the ghost script has some problems. Earlier, I have had never a problem with the fig.savefig command. But yesterday it started. It might be due to some changes made in the pygmt update.

Regards
Kumar

What happens when you run a simple code like below? Does ghostscript still have problems?

import pygmt
fig = pygmt.Figure()
fig.basemap(region=[0, 10, 0, 10], projection="X10c", frame=True)
fig.savefig("map.png", transparent=True)

Hi @seisman thank you for your consistent support. Your code absolutely runs fine and it saves the figures perfectly.

I figured out where is exactly the problem. When I give the file to save as a simple file name with png extension, it works perfectly; however, when I give the filename as a pathname plus the filename it shows that error.
For example, the following code doesn’t show any error.

import pygmt
fig = pygmt.Figure()
fig.basemap(region=[0, 10, 0, 10], projection="X10c", frame=True)
fig.savefig("map.png", transparent=True)

However, when I change the line 4 to:

fig.savefig("L:/PhD/ECA/figures/map.png", transparent=True)

I gives that error.

Please help me out with how to resolve this issue.

Does this directory exist?

I see very similar errors when the parent directories of the image don’t exist. See the issue report at https://github.com/GenericMappingTools/pygmt/issues/2092 if that’s also the cause of your issue.

Yes sir, it exists absolutely.

Perhaps you can try saving the image to the current directory (removing savepath from the code) and see if it works?

Try double back-slashes (instead of single forward-slash) between the folders …

Hi @Trevor,
Thank your for your input. I checked with your suggestions; unfortunately, its displaying the same error message.

Yes @seisman , that works fine. But earlier, it was also working with mentioning the directory. I wonder why its showing some error message.

What happens if you save it to a directory that doesn’t have whitespaces in the path names?

Hey @kripa,
does it work when you pass the file name with file path as argument through the fname parameter of the pygmt.Figure.savefig method:

import pygmt
fig = pygmt.Figure()
fig.basemap(region=[0, 10, 0, 10], projection="X10c", frame=True)
fig.savefig(fname="L:/PhD/ECA/figures/map.png", transparent=True)

Hi @yvonnefroehlich,
thank you very much. This works.