# Error in saving PyGMT figure

**URL:** <https://forum.generic-mapping-tools.org/t/error-in-saving-pygmt-figure/3230>\
**Category:** PyGMT Q&A\
**Tags:** gmt\
**Created:** [August 25, 2022, 2:56pm UTC](https://forum.generic-mapping-tools.org/t/error-in-saving-pygmt-figure/3230 "2022-08-25T14:56:14Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![ktripa](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ktripa/32/2084_2.png) [@ktripa](https://forum.generic-mapping-tools.org/u/ktripa)\
**Post date:** [August 25, 2022, 2:56pm UTC](https://forum.generic-mapping-tools.org/t/error-in-saving-pygmt-figure/3230/1 "2022-08-25T14:56:14Z")

</div>

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

 ![Capture](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/3/38dd069bbb959dc4d2b6a3076bc153b41ab29da2.jpeg)

---

<div class="post-metadata">

**Author:** ![seisman](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/seisman/32/4_2.png) [@seisman](https://forum.generic-mapping-tools.org/u/seisman)\
**Post date:** [August 26, 2022, 4:15am UTC](https://forum.generic-mapping-tools.org/t/error-in-saving-pygmt-figure/3230/2 "2022-08-26T04:15:33Z")

</div>

Could you please post the output of the following codes?

```python
import pygmt
pygmt.show_versions()

```

---

<div class="post-metadata">

**Author:** ![ktripa](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ktripa/32/2084_2.png) [@ktripa](https://forum.generic-mapping-tools.org/u/ktripa)\
**Post date:** [August 26, 2022, 2:47pm UTC](https://forum.generic-mapping-tools.org/t/error-in-saving-pygmt-figure/3230/3 "2022-08-26T14:47:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![seisman](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/seisman/32/4_2.png) [@seisman](https://forum.generic-mapping-tools.org/u/seisman)\
**Post date:** [August 27, 2022, 1:08am UTC](https://forum.generic-mapping-tools.org/t/error-in-saving-pygmt-figure/3230/4 "2022-08-27T01:08:39Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![ktripa](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ktripa/32/2084_2.png) [@ktripa](https://forum.generic-mapping-tools.org/u/ktripa)\
**Post date:** [August 29, 2022, 4:51pm UTC](https://forum.generic-mapping-tools.org/t/error-in-saving-pygmt-figure/3230/5 "2022-08-29T16:51:43Z")

</div>

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.

```auto
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:

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

```

I gives that error.

Please help me out with how to resolve this issue.

---

<div class="post-metadata">

**Author:** ![seisman](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/seisman/32/4_2.png) [@seisman](https://forum.generic-mapping-tools.org/u/seisman)\
**Post date:** [August 30, 2022, 2:08am UTC](https://forum.generic-mapping-tools.org/t/error-in-saving-pygmt-figure/3230/6 "2022-08-30T02:08:46Z")

</div>

> [@ktripa](#):
>
> `L:/PhD/ECA/figures/`

Does this directory exist?

---

<div class="post-metadata">

**Author:** ![seisman](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/seisman/32/4_2.png) [@seisman](https://forum.generic-mapping-tools.org/u/seisman)\
**Post date:** [August 30, 2022, 2:19am UTC](https://forum.generic-mapping-tools.org/t/error-in-saving-pygmt-figure/3230/7 "2022-08-30T02:19:03Z")

</div>

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](https://github.com/GenericMappingTools/pygmt/issues/2092) if that’s also the cause of your issue.

---

<div class="post-metadata">

**Author:** ![ktripa](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ktripa/32/2084_2.png) [@ktripa](https://forum.generic-mapping-tools.org/u/ktripa)\
**Post date:** [August 31, 2022, 10:17pm UTC](https://forum.generic-mapping-tools.org/t/error-in-saving-pygmt-figure/3230/8 "2022-08-31T22:17:23Z")

</div>

Yes sir, it exists absolutely.

---

<div class="post-metadata">

**Author:** ![seisman](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/seisman/32/4_2.png) [@seisman](https://forum.generic-mapping-tools.org/u/seisman)\
**Post date:** [September 1, 2022, 1:43am UTC](https://forum.generic-mapping-tools.org/t/error-in-saving-pygmt-figure/3230/9 "2022-09-01T01:43:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Trevor](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/trevor/32/1780_2.png) [@Trevor](https://forum.generic-mapping-tools.org/u/Trevor)\
**Post date:** [September 1, 2022, 1:42pm UTC](https://forum.generic-mapping-tools.org/t/error-in-saving-pygmt-figure/3230/10 "2022-09-01T13:42:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ktripa](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ktripa/32/2084_2.png) [@ktripa](https://forum.generic-mapping-tools.org/u/ktripa)\
**Post date:** [September 1, 2022, 5:53pm UTC](https://forum.generic-mapping-tools.org/t/error-in-saving-pygmt-figure/3230/11 "2022-09-01T17:53:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ktripa](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ktripa/32/2084_2.png) [@ktripa](https://forum.generic-mapping-tools.org/u/ktripa)\
**Post date:** [September 1, 2022, 5:55pm UTC](https://forum.generic-mapping-tools.org/t/error-in-saving-pygmt-figure/3230/12 "2022-09-01T17:55:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![seisman](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/seisman/32/4_2.png) [@seisman](https://forum.generic-mapping-tools.org/u/seisman)\
**Post date:** [September 2, 2022, 2:33am UTC](https://forum.generic-mapping-tools.org/t/error-in-saving-pygmt-figure/3230/13 "2022-09-02T02:33:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yvonnefroehlich](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/yvonnefroehlich/32/5064_2.png) [@yvonnefroehlich](https://forum.generic-mapping-tools.org/u/yvonnefroehlich)\
**Post date:** [September 2, 2022, 4:05pm UTC](https://forum.generic-mapping-tools.org/t/error-in-saving-pygmt-figure/3230/14 "2022-09-02T16:05:33Z")

</div>

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:

```python
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)

```

---

<div class="post-metadata">

**Author:** ![ktripa](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/ktripa/32/2084_2.png) [@ktripa](https://forum.generic-mapping-tools.org/u/ktripa)\
**Post date:** [September 2, 2022, 4:41pm UTC](https://forum.generic-mapping-tools.org/t/error-in-saving-pygmt-figure/3230/15 "2022-09-02T16:41:18Z")

</div>

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