import bilby fails out-of-the-box due to matplotlib backend issues
To reproduce (on macOS):
python -m virtualenv bilbyenv
./bilbyenv/bin/python -m pip install bilby
./bilbyenv/bin/python -c "import bilby"
The error presents as
/Users/duncan/tmp/./bilbyenv/bin/../lib/python3.6/site.py:165: DeprecationWarning: 'U' mode is deprecated
f = open(fullname, "rU")
13:10 bilby INFO : Running bilby version: 0.3.3:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/duncan/tmp/bilbyenv/lib/python3.6/site-packages/bilby/__init__.py", line 21, in <module>
from . import core, gw, hyper
File "/Users/duncan/tmp/bilbyenv/lib/python3.6/site-packages/bilby/core/__init__.py", line 2, in <module>
from . import likelihood, prior, result, sampler, utils
File "/Users/duncan/tmp/bilbyenv/lib/python3.6/site-packages/bilby/core/result.py", line 6, in <module>
import corner
File "/Users/duncan/tmp/bilbyenv/lib/python3.6/site-packages/corner/__init__.py", line 37, in <module>
from .corner import corner, hist2d, quantile
File "/Users/duncan/tmp/bilbyenv/lib/python3.6/site-packages/corner/corner.py", line 7, in <module>
import matplotlib.pyplot as pl
File "/Users/duncan/tmp/bilbyenv/lib/python3.6/site-packages/matplotlib/pyplot.py", line 2374, in <module>
switch_backend(rcParams["backend"])
...
File "/Users/duncan/tmp/bilbyenv/lib/python3.6/site-packages/matplotlib/backends/qt_compat.py", line 165, in <module>
raise ImportError("Failed to import any qt binding")
ImportError: Failed to import any qt binding
I think the fix is to update bilby.core.results
to either call matplotlib.use('agg')
before import matplotlib.pyplot
:
diff --git a/bilby/core/result.py b/bilby/core/result.py
index df4374b..ac55d84 100644
--- a/bilby/core/result.py
+++ b/bilby/core/result.py
@@ -1,12 +1,16 @@
import os
from distutils.version import LooseVersion
+from collections import OrderedDict, namedtuple
+
import numpy as np
import deepdish
import pandas as pd
-import corner
+
import matplotlib
+matplotlib.use('agg')
+
+import corner
import matplotlib.pyplot as plt
-from collections import OrderedDict, namedtuple
from . import utils
from .utils import logger, infer_parameters_from_function
I can happily post this patch as a merge request.