python3执行某一个程序时,报Segmentation fault (core dumped)错,但没有告知到底哪里出错,无法查问题
同时在根目录下生成core文件,典型的可以用gdb进行调试。这里用另外一个方法调试。
在主程序最开始加入两行代码:
import faulthandler
faulthandler.enable()
# 下面是原代码
再执行主程序,发现输出的信息很多:
igs@igs:~/eval_viewer $ python3 main.py
Fatal Python error: Segmentation fault
Current thread 0x00007f611cb7e740 (most recent call first):
File "/usr/lib/python3/dist-packages/gi/_option.py", line 47 in <module>
File "" , line 219 in _call_with_frames_removed
File "" , line 678 in exec_module
File "" , line 665 in _load_unlocked
File "" , line 955 in _find_and_load_unlocked
File "" , line 971 in _find_and_load
File "" , line 219 in _call_with_frames_removed
File "" , line 1023 in _handle_fromlist
File "/usr/lib/python3/dist-packages/gi/overrides/GLib.py", line 37 in <module>
File "" , line 219 in _call_with_frames_removed
File "" , line 678 in exec_module
File "" , line 665 in _load_unlocked
File "" , line 955 in _find_and_load_unlocked
File "" , line 971 in _find_and_load
File "" , line 994 in _gcd_import
File "/usr/lib/python3.6/importlib/__init__.py", line 126 in import_module
File "/usr/lib/python3/dist-packages/gi/overrides/__init__.py", line 125 in load_overrides
File "/usr/lib/python3/dist-packages/gi/importer.py", line 146 in load_module
File "" , line 626 in _load_backward_compatible
File "" , line 656 in _load_unlocked
File "" , line 955 in _find_and_load_unlocked
File "" , line 971 in _find_and_load
File "" , line 994 in _gcd_import
File "/usr/lib/python3.6/importlib/__init__.py", line 126 in import_module
File "/usr/lib/python3/dist-packages/gi/importer.py", line 145 in load_module
File "" , line 626 in _load_backward_compatible
File "" , line 656 in _load_unlocked
File "" , line 955 in _find_and_load_unlocked
File "" , line 971 in _find_and_load
File "" , line 994 in _gcd_import
File "/usr/lib/python3.6/importlib/__init__.py", line 126 in import_module
File "/usr/lib/python3/dist-packages/gi/importer.py", line 145 in load_module
File "" , line 626 in _load_backward_compatible
File "" , line 656 in _load_unlocked
File "" , line 955 in _find_and_load_unlocked
File "" , line 971 in _find_and_load
File "" , line 219 in _call_with_frames_removed
File "" , line 1023 in _handle_fromlist
File "/home/igs/.local/lib/python3.6/site-packages/matplotlib/backends/backend_gtk3.py", line 30 in <module>
File "" , line 219 in _call_with_frames_removed
File "" , line 678 in exec_module
File "" , line 665 in _load_unlocked
File "" , line 955 in _find_and_load_unlocked
File "" , line 971 in _find_and_load
File "" , line 219 in _call_with_frames_removed
File "" , line 1023 in _handle_fromlist
File "/home/igs/.local/lib/python3.6/site-packages/matplotlib/backends/backend_gtk3agg.py", line 8 in <module>
File "" , line 219 in _call_with_frames_removed
File "" , line 678 in exec_module
File "" , line 665 in _load_unlocked
File "" , line 955 in _find_and_load_unlocked
File "" , line 971 in _find_and_load
File "" , line 994 in _gcd_import
File "/usr/lib/python3.6/importlib/__init__.py", line 126 in import_module
File "/home/igs/.local/lib/python3.6/site-packages/matplotlib/pyplot.py", line 277 in backend_mod
File "/home/igs/.local/lib/python3.6/site-packages/matplotlib/pyplot.py", line 276 in switch_backend
File "/home/igs/.local/lib/python3.6/site-packages/matplotlib/pyplot.py", line 256 in switch_backend
File "/home/igs/.local/lib/python3.6/site-packages/matplotlib/__init__.py", line 703 in __getitem__
File "/home/igs/.local/lib/python3.6/site-packages/matplotlib/pyplot.py", line 2336 in <module>
File "" , line 219 in _call_with_frames_removed
File "" , line 678 in exec_module
File "" , line 665 in _load_unlocked
File "" , line 955 in _find_and_load_unlocked
File "" , line 971 in _find_and_load
File "" , line 219 in _call_with_frames_removed
File "" , line 1023 in _handle_fromlist
File "/home/igs/eval_viewer/eval_viewer/plot_panel.py", line 10 in <module>
File "" , line 219 in _call_with_frames_removed
File "" , line 678 in exec_module
File "" , line 665 in _load_unlocked
File "" , line 955 in _find_and_load_unlocked
File "" , line 971 in _find_and_load
File "/home/igs/eval_viewer/eval_viewer/data_load_form.py", line 13 in <module>
File "" , line 219 in _call_with_frames_removed
File "" , line 678 in exec_module
File "" , line 665 in _load_unlocked
File "" , line 955 in _find_and_load_unlocked
File "" , line 971 in _find_and_load
File "/home/igs/eval_viewer/eval_viewer/main_forms.py", line 9 in <module>
File "" , line 219 in _call_with_frames_removed
File "" , line 678 in exec_module
File "" , line 665 in _load_unlocked
File "" , line 955 in _find_and_load_unlocked
File "" , line 971 in _find_and_load
File "main.py", line 14 in <module>
Segmentation fault (core dumped)
igs@igs:~/eval_viewer $
从下往上看,main.py的line 14的内容为from eval_viewer.main_forms import MainWindow,即调用了main_forms.py,该文件为自己写的
然后main_forms.py的line 9的内容为from eval_viewer.data_load_form import DataLoadForm,即调用了data_load_form.py,该文件为自己写的
然后data_load_form.py的line13的内容为from eval_viewer.plot_panel import PlotPanel,即调用了plot_panel.py,该文件为自己写的
然后plot_panel.py的line10的内容为from matplotlib import pyplot as plt,即调用了matplotlib,该文件为安装的包。
果然是该包安装有问题,百度之即可。最终解决方法:
将原代码的
from matplotlib import pyplot as plt
修改为
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
成功解决!