@@ -981,9 +981,11 @@ def print_figure_impl(fh):
981
981
with open (tmpfile , 'w' , encoding = 'latin-1' ) as fh :
982
982
print_figure_impl (fh )
983
983
if mpl .rcParams ['ps.usedistiller' ] == 'ghostscript' :
984
- gs_distill (tmpfile , is_eps , ptype = papertype , bbox = bbox )
984
+ _try_distill (gs_distill ,
985
+ tmpfile , is_eps , ptype = papertype , bbox = bbox )
985
986
elif mpl .rcParams ['ps.usedistiller' ] == 'xpdf' :
986
- xpdf_distill (tmpfile , is_eps , ptype = papertype , bbox = bbox )
987
+ _try_distill (xpdf_distill ,
988
+ tmpfile , is_eps , ptype = papertype , bbox = bbox )
987
989
_move_path_to_path_or_stream (tmpfile , outfile )
988
990
989
991
else :
@@ -1141,10 +1143,12 @@ def write(self, *args, **kwargs):
1141
1143
1142
1144
if (mpl .rcParams ['ps.usedistiller' ] == 'ghostscript'
1143
1145
or mpl .rcParams ['text.usetex' ]):
1144
- gs_distill (tmpfile , is_eps , ptype = papertype , bbox = bbox ,
1145
- rotated = psfrag_rotated )
1146
+ _try_distill (gs_distill ,
1147
+ tmpfile , is_eps , ptype = papertype , bbox = bbox ,
1148
+ rotated = psfrag_rotated )
1146
1149
elif mpl .rcParams ['ps.usedistiller' ] == 'xpdf' :
1147
- xpdf_distill (tmpfile , is_eps , ptype = papertype , bbox = bbox ,
1150
+ _try_distill (xpdf_distill ,
1151
+ tmpfile , is_eps , ptype = papertype , bbox = bbox ,
1148
1152
rotated = psfrag_rotated )
1149
1153
1150
1154
_move_path_to_path_or_stream (tmpfile , outfile )
@@ -1198,6 +1202,13 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble,
1198
1202
return psfrag_rotated
1199
1203
1200
1204
1205
+ def _try_distill (func , * args , ** kwargs ):
1206
+ try :
1207
+ func (* args , ** kwargs )
1208
+ except mpl .ExecutableNotFoundError as exc :
1209
+ _log .warning ("%s. Distillation step skipped." , exc )
1210
+
1211
+
1201
1212
def gs_distill (tmpfile , eps = False , ptype = 'letter' , bbox = None , rotated = False ):
1202
1213
"""
1203
1214
Use ghostscript's pswrite or epswrite device to distill a file.
@@ -1239,6 +1250,9 @@ def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
1239
1250
operators. This distiller is preferred, generating high-level postscript
1240
1251
output that treats text as text.
1241
1252
"""
1253
+ mpl ._get_executable_info ("gs" ) # Effectively checks for ps2pdf.
1254
+ mpl ._get_executable_info ("pdftops" )
1255
+
1242
1256
pdffile = tmpfile + '.pdf'
1243
1257
psfile = tmpfile + '.ps'
1244
1258
0 commit comments