Skip to content

Commit 8b7a6d7

Browse files
committed
Merge pull request #671 from mwaskom/fix/matplotlib_backend
Set Matplotlib backend robustly during distributed execution
2 parents 3c779c1 + e4ee1f7 commit 8b7a6d7

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

nipype/pipeline/plugins/base.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,15 @@ def create_pyscript(node, updatehash=False, store_exception=True):
105105
os.makedirs(batch_dir)
106106
pkl_file = os.path.join(batch_dir, 'node_%s.pklz' % suffix)
107107
savepkl(pkl_file, dict(node=node, updatehash=updatehash))
108+
mpl_backend = node.config["execution"]["matplotlib_backend"]
108109
# create python script to load and trap exception
109110
cmdstr = """import os
110111
import sys
112+
try:
113+
import matplotlib
114+
matplotlib.use('%s')
115+
except ImportError:
116+
pass
111117
from nipype import config, logging
112118
from nipype.utils.filemanip import loadpkl, savepkl
113119
from socket import gethostname
@@ -153,7 +159,7 @@ def create_pyscript(node, updatehash=False, store_exception=True):
153159
report_crash(info['node'], traceback, gethostname())
154160
raise Exception(e)
155161
"""
156-
cmdstr = cmdstr % (pkl_file, batch_dir, node.config, suffix)
162+
cmdstr = cmdstr % (mpl_backend, pkl_file, batch_dir, node.config, suffix)
157163
pyscript = os.path.join(batch_dir, 'pyscript_%s.py' % suffix)
158164
fp = open(pyscript, 'wt')
159165
fp.writelines(cmdstr)

0 commit comments

Comments
 (0)