fig.savefig() problem

Hi all,
When I want to show or savefig the figure, the error( with -V):

psconvert [DEBUG]: gmt_check_executable: Pass to popen: [gs --version 2> /dev/null]
psconvert [DEBUG]: gs --version 2> /dev/null was successful
psconvert [DEBUG]: Ghostscript version: 9.54.0
psconvert [DEBUG]: Use PS filename /Users/tong/.gmt/sessions/gmt_session.53684/
psconvert [DEBUG]: Hidden PS file /Users/tong/.gmt/sessions/gmt_session.53684/ found
psconvert [DEBUG]: Complete partial PS file /Users/tong/.gmt/sessions/gmt_session.53684/
psconvert [DEBUG]: Size of half-baked PS file = 24216.
psconvert [DEBUG]: Fattened up PS file /Users/tong/.gmt/sessions/gmt_session.53684/
psconvert [INFORMATION]: Processing /Users/tong/.gmt/sessions/gmt_session.53684/…
psconvert [INFORMATION]: Find HiResBoundingBox …
psconvert [DEBUG]: Running: gs -q -dNOSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox -DPSL_no_pagefill -dMaxBitmap=2147483647 -dUseFastColor=true ‘/Users/tong/.gmt/sessions/gmt_session.53684/’ 2> ‘/Users/tong/.gmt/sessions/gmt_session.53684/’
gs: Interpreter revision (9540) does not match revision (9533).
psconvert [ERROR]: System call [gs -q -dNOSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox -DPSL_no_pagefill -dMaxBitmap=2147483647 -dUseFastColor=true ‘/Users/tong/.gmt/sessions/gmt_session.53684/’ 2> ‘/Users/tong/.gmt/sessions/gmt_session.53684/’] returned error 256.
psconvert [DEBUG]: Delete /Users/tong/.gmt/sessions/gmt_session.53684/

I have reconstructed the environment and update gmt to 6.2.0.
There is pygmt.show_version() information.
(I install pygmt in my work environment splitpy_1 to test it. )

PyGMT information:
version: v0.4.1
System information:
python: 3.7.10 | packaged by conda-forge | (default, Feb 19 2021, 15:59:12) [Clang 11.0.1 ]
executable: /Users/tong/opt/anaconda3/envs/split_1/bin/python
machine: Darwin-19.6.0-x86_64-i386-64bit
Dependency information:
numpy: 1.21.2
pandas: 1.3.2
xarray: 0.19.0
netCDF4: 1.5.7
packaging: 21.0
ghostscript: 9.54.0
gmt: 6.2.0
GMT library information:
binary dir: /Users/tong/opt/anaconda3/envs/split_1/bin
cores: 4
grid layout: rows
library path: /Users/tong/opt/anaconda3/envs/split_1/lib/libgmt.dylib
padding: 2
plugin dir: /Users/tong/opt/anaconda3/envs/split_1/lib/gmt/plugins
share dir: /Users/tong/opt/anaconda3/envs/split_1/share/gmt
version: 6.2.0

Please help me. This is a big problem. Thx !

Hi @JingHuiTong, thanks for posting a detailed report! Your list of dependencies from pygmt.show_versions() seems ok, but I did notice this line in the error log:

gs: Interpreter revision (9540) does not match revision (9533).

So your installed ghostscript (gs) is 9.54.0, but it seems to be thinking that your postscript (ps) file is built with ghostscript 9.53.3. Did you try re-starting your Python kernel and re-creating the figure from scratch? Something might have went wrong when you upgraded to gmt 6.2.0.

Hi @weiji14,
Thanks for your reply!
In fact, this problem was happened before updating gmt6.2.0.
Because I encountered this situation, I reinstalled pygmt and update gmt.

Surely, I have tried to re-starting the kernel and re-creating the figure.
I also tried these steps in jupyter lab and iTerms.
But the problem still existed.

Could you try:

  1. running gmt clear all in the terminal (to clear the session cache), and
  2. run which gs and show us to output, just need to check that there’s not another ghostscript library somewhere in your $PATH.

Hi @weiji14,
I followed your suggestion.
If I don’t activate the environment, it successfully uses GMT psconvert.
When I activate the environment, it failed.

Please see the details. Thanks for your patient assistance.

[NO activate environment]
Screen Shot 2021-08-19 at 1.27.58 PM|520x129

[Activate environment]

I recommend trying to run your PyGMT code in an environment without the GMT bundle in your path. Did you add the following commands to your .bashrc file in order to use the GMT bundle in terminals not initialized by the app?

        a) export GMTHOME=/Applications/
        b) add $GMTHOME/bin to your path
        c) export PROJ_LIB=$GMTHOME/share/proj
        d) export GS_LIB=$GMTHOME/share/ghostscript/9.53.3/Resource/Init
        e) export MAGICK_CONFIGURE_PATH=$GMTHOME/lib/GraphicsMagick/config

If so, try commenting them out so that there is no confusion between the conda GMT installation and the bundle installation.

Dear @maxrjones
I followed your suggestions, it finally can show the figure !!! :grinning:
This solution can temporally solve my problems.
But I want to solve the root reason for this problem because I will use gmt someday.

There’s a conflict with the 6.2.0 bundle using a different version of ghostscript than your conda environment that causes problems when both are in your path.

To use GMT, you can either (1) activate the same conda environment that you use for PyGMT (which has GMT installed as a dependency), (2) install a gmt specific conda environment (see below) or (3) temporarily add the bundle to your path and source the associated variables. Options 1 or 2 are the simplest.

Instructions for a gmt specific environment:

conda create --name gmt --channel conda-forge gmt

Then whenever you want to use GMT you can activate the environment:

conda activate gmt