当前位置: 代码迷 >> 综合 >> 解决报错:Assertion failed: (NSViewIsCurrentlyBuildingLayerTreeForDisplay() != currently...
  详细解决方案

解决报错:Assertion failed: (NSViewIsCurrentlyBuildingLayerTreeForDisplay() != currently...

热度:84   发布时间:2023-11-01 11:03:33.0

报错:Assertion failed: (NSViewIsCurrentlyBuildingLayerTreeForDisplay() != currentlyBuildingLayerTree), function NSViewSetCurrentlyBuildingLayerTreeForDisplay, file /AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1894.60.100/AppKit.subproj/NSView.m, line 13568.

在flask框架下使用matplotlib模块保存图片,每次执行完flask就会退出,并且报以上错误,还要在flask run才行,解决方法

新加两行代码

import matplotlib
matplotlib.use('Agg')

如下是我保存图片的方法

import numpy as np
import matplotlib.pyplot as plt
import matplotlib    #添加这一行
matplotlib.use('Agg')    #还有这一行,就不会报错了def display_tif(original_data, denoise_data, n):list = range(n)x = np.array(list)plt.plot(x, original_data, 'ro', color='blue', label='original_data')plt.plot(x, denoise_data, color='red', label='denoise_data')plt.xlabel('x')plt.ylabel('y')plt.title('title')plt.legend()plt.savefig(r'out.tif')

参考:原因、参考

  相关解决方案