1
我在使用python編程樹莓派1.我得到這個錯誤,當我嘗試使用plt.savefig保存圖時,甚至如果情節的內容是單個值。我有一個運行在主程序上的Tkinter,我有單獨的線程通過調用另一個.py文件中的函數來進行一些計算,plt.savefig處於這些函數之一中。直接調用第二個.py文件時,plt.savefig可以正常工作,所以我想這與我的線程有關。我的知識是一種有限的,我真的很感激一些幫助:(Python:OverflowError:Python int太大,將圖像保存爲圖像時轉換爲C long
編輯:
import threading
import time
import matplotlib.pyplot as plt
def saveplot():
plt.plot(3)
plt.savefig("plot.jpg")
time.sleep(10)
threads = []
t = threading.Thread(target=saveplot)
threads.append(t)
t.start()
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "Slett.py", line 6, in saveplot
plt.savefig("plot.jpg")
File "/usr/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 578, in savefig
draw() # need this if 'transparent=True' to reset colors
File "/usr/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 571, in draw
get_current_fig_manager().canvas.draw()
File "/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.py", line 350, in draw
tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2)
File "/usr/lib/python2.7/dist-packages/matplotlib/backends/tkagg.py", line 21, in blit
_tkagg.tkinit(tk.interpaddr(), 1)
OverflowError: Python int too large to convert to C long
單數你想爲了節省太大,C的長度只能達到2^63 - 1,但是你的數字要大於這個數字,或者你的數字是負數,小於 - (2^63)。 – Kevin
@Kevin我想'2^63-1'只在64位系統上,我相信無論平臺多少都是'sys.maxsize'。 –
@ TadhgMcDonald-Jense n:這就是'ssize_t',通常但不總是和'long'一樣(Windows是一個很好的反例,它有32位長和64位指針)。 – Kevin