dawlib dawlib - 3 months ago 42
Python Question

"Segmentation Fault" in matplotlib running example Librosa script

After many issues I've installed Librosa (https://github.com/librosa/librosa) on Linux Mint 18 Mate x64. When I want to run example script, e.g.: http://librosa.github.io/librosa/generated/librosa.feature.tempogram.html#librosa.feature.tempogram, it crashes with "Segmentation Fault" error:

$ python librosa-feature-tempogram-1.py
/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt5.py:140: Warning: g_main_context_push_thread_default: assertion 'acquired_context' failed
qApp = QtWidgets.QApplication([str(" ")])
Segmentation fault


I've tried to debug it line-by-line and there is result:

$ python
Python 2.7.12 (default, Jul 1 2016, 15:12:24)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import librosa

>>> # Visualize an STFT power spectrum
...
>>> import matplotlib.pyplot as plt
>>> y, sr = librosa.load(librosa.util.example_audio_file())

>>> plt.figure(figsize=(12, 8))
/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt5.py:140: Warning: g_main_context_push_thread_default: assertion 'acquired_context' failed
qApp = QtWidgets.QApplication([str(" ")])
Segmentation fault


Probably there is some issue with matplotlib library and Qt (5.7.0). Moreover, I remember I had many issues when installing Librosa, including matplotlib, so it could be some installation issue. However, I don't know how to solve it. I hope somebody will have helpful clues for me.

Answer

Finally, I've solved this issue by installing these packages: sudo apt-get install tk-dev libpng-dev libffi-dev dvipng texlive-latex-base and reinstalling matplotlib using pip. I have also changed background in matplotlib on TkAgg. There is a beginning of a code with import statements:

import librosa
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt

Now it works perfectly.