gpt4 book ai didi

Python绘图图像保存错误

转载 作者:太空宇宙 更新时间:2023-11-03 11:16:26 24 4
gpt4 key购买 nike

我是 Python 新手。我已经使用 Django 编写了 Web 服务来将图像保存在服务器中。我正在尝试使用下面的代码将绘图保存为图像,并且在 Python 抛出错误之后它可以正常工作 3 次。如何解决此问题?

Exception ignored in: <bound method Image.__del__ of <tkinter.PhotoImage object at 0x000000000FE40048>>
Traceback (most recent call last):
File "c:\dev\lib\tkinter\__init__.py", line 3504, in __del__
self.tk.call('image', 'delete', self.name)
RuntimeError: main thread is not in main loop
Exception ignored in: <bound method Image.__del__ of <tkinter.PhotoImage object at 0x0000000010996438>>
Traceback (most recent call last):
File "c:\dev\lib\tkinter\__init__.py", line 3504, in __del__
self.tk.call('image', 'delete', self.name)
RuntimeError: main thread is not in main loop
Exception ignored in: <bound method Image.__del__ of <tkinter.PhotoImage object at 0x0000000010B8BF98>>
Traceback (most recent call last):
File "c:\dev\lib\tkinter\__init__.py", line 3504, in __del__
self.tk.call('image', 'delete', self.name)
RuntimeError: main thread is not in main loop
Tcl_AsyncDelete: async handler deleted by the wrong thread


**PYTHON CODE**
fileName = id_generator()+".png"
filePath = settings.MEDIA_ROOT+"/"+fileName
fig.savefig(filePath, dpi=fig.dpi)
plt.close(fig)
Response(fileName, status=status.HTTP_201_CREATED)

Package Version
------------------- ---------
cassandra-driver 3.14.0
certifi 2018.4.16
cycler 0.10.0
Django 2.0.5
djangorestframework 3.8.2
kiwisolver 1.0.1
matplotlib 2.2.2
numpy 1.14.4
pandas 0.23.0
pip 10.0.1
pyparsing 2.2.0
python-dateutil 2.7.3
pytz 2018.4
scikit-learn 0.19.1
scipy 1.1.0
setuptools 39.2.0
six 1.11.0
wheel 0.31.1
wincertstore 0.2

最佳答案

我在不同的情况下遇到了同样的问题。如 answer 中所述,应添加 matplotlib.use('Agg')。这应该可以解决您的问题。

关于Python绘图图像保存错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50848127/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com