m1 Mac matplotlib 后台画图报错 NSInternalInconsistencyException

m1 Mac matplotlib 后台画图报错 NSInternalInconsistencyException_第1张图片

在flask项目运行的过程中使用matplotlib画图报错并出现如下错误,错误主要为:
Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘NSWindow drag regions should only be invalidated on the Main Thread!’

解决方法
设置matplotlib在后台运行,不显示前台GUI

import matplotlib.pyplot as plt
plt.switch_backend('agg')

你可能感兴趣的:(matplotlib,macos,python)