diff --git a/bob/bio/base/script/evaluate.py b/bob/bio/base/script/evaluate.py
index b239e235c94ae1d5d9d57e7162246e7149f95368..562c5956357481b064f846e43b5d74f4d83288f5 100644
--- a/bob/bio/base/script/evaluate.py
+++ b/bob/bio/base/script/evaluate.py
@@ -7,6 +7,14 @@ You can set the environment variable BOB_NO_STYLE_CHANGES to any value to avoid
 this script from changing the matplotlib style values. """
 
 from __future__ import print_function
+
+# matplotlib stuff
+import matplotlib
+from matplotlib import pyplot
+pyplot.switch_backend('agg')  # switch to non-X backend
+from matplotlib.backends.backend_pdf import PdfPages
+
+# import bob.measure after matplotlib, so that it cannot define the backend
 import bob.measure
 
 import argparse
@@ -14,11 +22,6 @@ import numpy
 import math
 import os
 
-# matplotlib stuff
-import matplotlib
-matplotlib.use('pdf')  # avoids TkInter threaded start
-from matplotlib import pyplot
-from matplotlib.backends.backend_pdf import PdfPages
 
 if not os.environ.get('BOB_NO_STYLE_CHANGES'):
   # make the fig size smaller so that everything becomes bigger
@@ -457,4 +460,4 @@ def main(command_line_parameters=None):
           pdf.savefig(_plot_dir(cmcs_eval, fars, args.rank, colors, args.legends, args.title[1] if args.title is not None else "DIR curve for evaluation set", args.legend_font_size, args.legend_position), bbox_inches='tight')
         pdf.close()
       except RuntimeError as e:
-        raise RuntimeError("During plotting of DIR curves, the following exception occured:\n%s")
+        raise RuntimeError("During plotting of DIR curves, the following exception occured:\n%s" % e)
diff --git a/bob/bio/base/test/test_scripts.py b/bob/bio/base/test/test_scripts.py
index c8131ed73daecd26606bebc347e10e22c00fb387..cb0f13b228251c5ce73190b4988a54d5fc65ebf1 100644
--- a/bob/bio/base/test/test_scripts.py
+++ b/bob/bio/base/test/test_scripts.py
@@ -1,7 +1,4 @@
 
-
-import bob.measure
-
 import os
 import shutil
 import tempfile
@@ -23,6 +20,7 @@ data_dir = pkg_resources.resource_filename('bob.bio.base', 'test/data')
 
 def _verify(parameters, test_dir, sub_dir, ref_modifier="", score_modifier=('scores',''), counts=3, check_zt=True):
   from bob.bio.base.script.verify import main
+  import bob.measure
   try:
     main(parameters)
 
@@ -248,8 +246,9 @@ def test_verify_filelist():
       '--preferred-package', 'bob.bio.base'
   ]
 
+  from bob.bio.base.script.verify import main
+  import bob.measure
   try:
-    from bob.bio.base.script.verify import main
     main(parameters)
 
     # assert that the score file exists
@@ -292,8 +291,9 @@ def test_verify_missing():
       '--imports', 'bob.bio.base.test.dummy'
   ]
 
+  from bob.bio.base.script.verify import main
+  import bob.measure
   try:
-    from bob.bio.base.script.verify import main
     main(parameters)
 
     # assert that the score file exists
@@ -448,6 +448,7 @@ def test_fusion():
 
   # execute the script
   from bob.bio.base.script.fuse_scores import main
+  import bob.measure
   try:
     main(parameters)