簡體   English   中英

m1 mac,python 在 matplotlib 和 jupyter 筆記本中使用 osx 作為后端時斷言失敗和崩潰

[英]m1 mac, python assertion failure and crashes when using osx as backend in matplotlib & jupyter notebook

當我使用 jupyter notebook 時發生錯誤

我正在使用帶有 monterey 12.1 的 m1 macbook pro,這是正在編寫的最新版本

這是我的代碼

import matplotlib.pyplot as plt
%matplotlib osx

這是錯誤消息

2021-12-23 18:16:19.185 python[25121:1046786] *** Assertion failure in +[NSEvent otherEventWithType:location:modifierFlags:timestamp:windowNumber:context:subtype:data1:data2:], NSEvent.m:740
2021-12-23 18:16:19.199 python[25121:1046786] *** Assertion failure in +[NSEvent otherEventWithType:location:modifierFlags:timestamp:windowNumber:context:subtype:data1:data2:], NSEvent.m:740

此消息只是重復數百次,最后顯示遞歸錯誤並崩潰

這是遞歸錯誤消息

Exception ignored on calling ctypes callback function: <function stop at 0x122abff70>
Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/miniforge/base/envs/strategy/lib/python3.9/site-packages/ipykernel/_eventloop_macos.py", line 107, in stop
    _triggered.set()
  File "/opt/homebrew/Caskroom/miniforge/base/envs/strategy/lib/python3.9/threading.py", line 544, in set
    self._cond.notify_all()
  File "/opt/homebrew/Caskroom/miniforge/base/envs/strategy/lib/python3.9/threading.py", line 381, in notify_all
    self.notify(len(self._waiters))
  File "/opt/homebrew/Caskroom/miniforge/base/envs/strategy/lib/python3.9/threading.py", line 361, in notify
    if not self._is_owned():
  File "/opt/homebrew/Caskroom/miniforge/base/envs/strategy/lib/python3.9/threading.py", line 274, in _is_owned
    if self._lock.acquire(False):
RecursionError: maximum recursion depth exceeded while calling a Python object

而其他交互式后端工作正常,例如 nbAgg

我無法回答您的問題,但會添加更多信息,因為我對此進行了更詳細的討論:

嘗試創建未在筆記本中內聯的數據圖時,會出現一些錯誤行為。 要么發生上述錯誤,要么顯示圖表並彈出崩潰報告對話框。

這是使用以下設置進行測試的:

macOS Monterey 12.1(M1 ARM 處理器)
Python:3.9.1
matplotlib:3.5.0
木星:1.0.0
筆記本:6.4.7
(使用虛擬環境)

示例 1:

import numpy as np
import matplotlib.pyplot as plt
%matplotlib osx
plt.plot(np.arange(100))

這會導致上面提到的堆棧溢出鏈接中描述的錯誤。 調用 plot() 的單元格似乎被反復評估。 有時,由於重復調用,plot window 會顯示但卡住。

示例 2:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib
matplotlib.use('QtAgg')
plt.plot(np.arange(100))

這順利通過,除了沒有顯示 plot 的事實。 最后一個單元格的調用返回 [<matplotlib.lines.Line2D at 0x12f076bf1>] 。 添加 plt.show() 也無濟於事。 使用 TkAgg 后端,觀察到相同的行為。 有趣的是,當使用 MacOSX 作為后端時,我預計會發生示例 1 中的錯誤,但行為與其他后端相同......

我仍然不清楚,在上述條件下,如何在筆記本外部打開繪圖而不會出現任何錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM