GenericMappingTools / pygmt

A Python interface for the Generic Mapping Tools.
https://www.pygmt.org
BSD 3-Clause "New" or "Revised" License
758 stars 220 forks source link

Error with psconvert finding gswin64 #829

Closed weiji14 closed 3 years ago

weiji14 commented 3 years ago

Description of the problem

Trying to save or show a figure results in an error with ghostscript (gs) not found with a fresh conda install on Windows 10. This is with following the installation instructions at https://github.com/GenericMappingTools/pygmt/blob/v0.2.1/CONTRIBUTING.md#setting-up-your-environment. Note sure if there's something wrong with the conda gmt package at https://github.com/conda-forge/gmt-feedstock?

Full code that generated the error

pytest --verbose -x

Full error message

(pygmt) PS H:\github\pygmt> pytest --verbose -x
======================================== test session starts ========================================
platform win32 -- Python 3.8.6, pytest-6.2.2, py-1.10.0, pluggy-0.13.1 -- C:\Users\username\.conda\envs
\pygmt\python.exe
cachedir: .pytest_cache
Matplotlib: 3.3.4
Freetype: 2.10.4
rootdir: H:\github\pygmt, configfile: pyproject.toml
plugins: cov-2.11.1, mpl-0.12
collected 0 items / 1 error

============================================== ERRORS ===============================================
________________________ ERROR collecting examples/gallery/coast/borders.py _________________________
examples\gallery\coast\borders.py:25: in <module>
    fig.show()
H:\github\pygmt\pygmt\figure.py:277: in show
    png = self._preview(
H:\github\pygmt\pygmt\figure.py:349: in _preview
    self.savefig(fname, dpi=dpi, **kwargs)
H:\github\pygmt\pygmt\figure.py:232: in savefig
    self.psconvert(prefix=prefix, fmt=fmt, crop=crop, **kwargs)
H:\github\pygmt\pygmt\helpers\decorators.py:267: in new_module
    return module_func(*args, **kwargs)
H:\github\pygmt\pygmt\helpers\decorators.py:411: in new_module
    return module_func(*args, **kwargs)
H:\github\pygmt\pygmt\figure.py:173: in psconvert
    lib.call_module("psconvert", build_arg_string(kwargs))
H:\github\pygmt\pygmt\clib\session.py:503: in call_module
    raise GMTCLibError(
E   pygmt.exceptions.GMTCLibError: Module 'psconvert' failed with status code 78:
E   psconvert [ERROR]: System call [@gswin64c -q -dNOSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox -DPSL_no_pa
gefill -dMaxBitmap=2147483647 -dUseFastColor=true "C:/Users/username/.gmt/sessions/gmt_session.13356/gm
t_1.ps-" 2> "C:/Users/username/.gmt/sessions/gmt_session.13356/psconvert_12992c.bb"] returned error 1.
------------------------------------------ Captured stderr ------------------------------------------
The system cannot find the path specified.
The system cannot find the path specified.
psconvert [ERROR]: System call [@gswin64c -q -dNOSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox -DPSL_no_pagefi
ll -dMaxBitmap=2147483647 -dUseFastColor=true "C:/Users/username/.gmt/sessions/gmt_session.13356/gmt_1.
ps-" 2> "C:/Users/username/.gmt/sessions/gmt_session.13356/psconvert_12992c.bb"] returned error 1.
====================================== short test summary info ======================================
ERROR examples/gallery/coast/borders.py - pygmt.exceptions.GMTCLibError: Module 'psconvert' failed ...

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
========================================= 1 error in 2.92s ==========================================

I've hit this issue a few times now since late last year, and had a friend who had a similar issue with not finding ghostscript last month, and I think the workaround he did was to manually download the ghostscript executable (gswin32.exe?) and place it at the right path. Not sure if it's a problem with our university's Windows system (we have funny network drives) or something with the gmt conda package not linking to ghostscript properly. This looks similar-ish to issue #393

Edit: Might be an upstream gmt issue actually. Running pure GMT doesn't work either:

gmt basemap -R0/1/0/1 -JX1 -Baf -Vi -png map
begin [INFORMATION]: Creating a workflow directory C:/Users/username/.gmt/sessions/gmt_session.13584
basemap [INFORMATION]: Constructing the basemap
basemap [INFORMATION]: Auto-frame interval for x-axis (item 0): a0.2f0.1
basemap [INFORMATION]: Auto-frame interval for y-axis (item 0): a0.2f0.1
basemap [INFORMATION]: Map scale is 0.001 km per cm or 1:100.
end [INFORMATION]: Process GMT figure queue: 1 figures found
end [INFORMATION]: Processing GMT figure #0 [map png ]
The system cannot find the path specified.
psconvert [INFORMATION]: Processing C:/Users/username/.gmt/sessions/gmt_session.13584/gmt_0.ps-...
psconvert [INFORMATION]: Find HiResBoundingBox ...
The system cannot find the path specified.
psconvert [ERROR]: System call [@"C:/Users/username/.conda/envs/pygmt/Library/bin/gswin64c.exe" -q -dNOSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox -DPSL_no_pagefill -dMaxBitmap=2147483647 -dUseFastColor=true "C:/Users/username/.gmt/sessions/gmt_session.13584/gmt_0.ps-" 2> "C:/Users/username/.gmt/sessions/gmt_session.13584/psconvert_12268c.bb"] returned error 1.
end [ERROR]: Failed to call psconvert
end [ERROR]: gmtinit_process_figures returned error 78
end [INFORMATION]: Destroying the current workflow directory C:/Users/username/.gmt/sessions/gmt_session.13584
basemap [ERROR]: Unable to call module end for a one-liner plot.

System information

Please paste the output of python -c "import pygmt; pygmt.show_versions()":

PyGMT information:
  version: v0.2.2.dev90+g8e2b3691
System information:
  python: 3.8.6 | packaged by conda-forge | (default, Jan 25 2021, 22:54:47) [MSC v.1916 64 bit (AMD64)]
  executable: C:\Users\username\.conda\envs\pygmt\python.exe
  machine: Windows-10-10.0.16299-SP0
Dependency information:
  numpy: 1.19.5
  pandas: 1.2.1
  xarray: 0.16.2
  netCDF4: 1.5.5.1
  packaging: 20.8
  ghostscript: 9.53.3
  gmt: 6.1.1
GMT library information:
  binary dir: C:/Users/username/.conda/envs/pygmt
  cores: 6
  grid layout: rows
  library path: C:/Users/username/.conda/envs/pygmt/Library/bin/gmt.dll
  padding: 2
  plugin dir: C:/Users/username/.conda/envs/pygmt/Library/bin/gmt_plugins
  share dir: C:/Users/username/.conda/envs/pygmt/Library/share/gmt
  version: 6.1.1
seisman commented 3 years ago

Are you using a 32 bit Windows?

Can you check if c:/Users/username/.conda/envs/pygmt/Library/bin/gswin64c.exe or c:/Users/username/.conda/envs/pygmt/Library/bin/gswin32c.exe exist?

weiji14 commented 3 years ago

I'm on 64-bit Windows, and yes, both files exist and I can open them fine, so not sure why GMT isn't finding them

(pygmt) PS H:\github\pygmt> ls C:\Users\username\.conda\envs\pygmt\Library\bin\gswin*

    Directory: C:\Users\username\.conda\envs\pygmt\Library\bin

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        9/11/2020  10:46 AM         102912 gswin64.exe
-a----        9/11/2020  10:46 AM          92672 gswin64c.exe
seisman commented 3 years ago

@weiji14 Perhaps you can try to install the GMT dev version instead?

seisman commented 3 years ago

something with the gmt conda package not linking to ghostscript properly.

gmt is not linked to ghostscript. It simply tries to search for ghostscript in Windows' registry or gswin64c in PATH.

One of the workarounds may be installing Ghostscript using the official installer, which updates the Windows registry.

weiji14 commented 3 years ago

gmt is not linked to ghostscript. It simply tries to search for ghostscript in Windows' registry or gswin64c in PATH.

One of the workarounds may be installing Ghostscript using the official installer, which updates the Windows registry.

Haven't got admin permissions on my university Windows system so changing the registry is not possible. But I'll try and install the dev version (i.e. conda install -c conda-forge/label/dev gmt) and see if it works.

Edit: Nope, using GMT 6.2.0_e1b6a15_2021.02.02 still gives an error with using gswin64c.exe

seisman commented 3 years ago

This is not a PyGMT issue, and all PyGMT tests work well on Windows.

Close it? @weiji14

weiji14 commented 3 years ago

Ok, haven't had time to reproduce this properly. I'll close for now.