0

在许多问题之后,我在 Linux Mint 18 Mate x64 上安装了 Librosa ( https://github.com/librosa/librosa )。当我想运行示例脚本时,例如:http://librosa.github.io/librosa/generated/librosa.feature.tempogram.html#librosa.feature.tempogram,它会因“Segmentation Fault”错误而崩溃:

$ 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

我试图逐行调试它,结果如下:

$ 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

matplotlib 库和 Qt (5.7.0) 可能存在一些问题。此外,我记得我在安装 Librosa 时遇到了很多问题,包括 matplotlib,所以可能是一些安装问题。但是,我不知道如何解决它。我希望有人能为我提供有用的线索。

4

1 回答 1

2

最后,我通过安装这些包解决了这个问题:sudo apt-get install tk-dev libpng-dev libffi-dev dvipng texlive-latex-base并使用pip重新安装matplotlib。我还在TkAgg上更改了matplotlib的背景。有一个带有 import 语句的代码的开头:

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

现在它完美地工作了。

于 2016-08-31T22:17:12.693 回答