You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to run PebbleCounts on a 2013 Mac Pro (Catalina 10.15.7). I followed the installation instructions for Mac verbatim from the manual, and found that both PebbleCounts.py and PebbleCountsAuto.py run smoothly up until the program needs to open a window, at which point Python crashes and throws the following exception:
I have reproduced everything on a 2019 MacBook Pro (Big Sur 11.2.1), and the errors are identical between the two machines.
I have found discussions of matplotlib backend issues on Mac, which generally advise using TkAgg (MTG/sms-tools#36). This solution is already implemented in PebbleCounts.py, and did not work for me. I am uncertain as to why Tk in general seems not to work in my pebblecounts Conda environment -- perhaps backwards incompatibility between Python 3.6 and Tk 8.6? Created as written in the manual, the pebblecounts environment uses Python 3.6.10 and Tk 8.6.10, both Conda’s default packages. These versions seem to be the only viable options, as PebbleCounts requires Python 3.6 for all necessary dependencies to work and Tk 8.5 has serious bugs that affect macOS (https://www.python.org/download/mac/tcltk/).
Solution
While I have not been able to get Tk to work in the pebblecounts environment, I was able to get PebbleCounts.py and PebbleCountsAuto.py running smoothly by making two edits:
In PCfunctions.py, omitting the portion of resizeWin() that uses tkinter:
Original resizeWin()
def resizeWin(img, resize_factor=0.7):
"""
Get the system screen resolution and resize input image by a factor. Factor
must be in the range (0, 1].
"""
from sys import platform as sys_pf
if 'win' in sys_pf:
# this import needs to be within the function or else openCV throws errors
import tkinter as tk
root = tk.Tk()
resize_factor = (1 - resize_factor) + 1
sys_w, sys_h = root.winfo_screenwidth()/resize_factor, root.winfo_screenheight()/resize_factor
root.destroy()
root.quit()
del root
else:
resize_factor = (1 - resize_factor) + 1
sys_w, sys_h = 1920/resize_factor, 1080/resize_factor
scale_width = sys_w / img.shape[1]
scale_height = sys_h / img.shape[0]
dimensions = min(scale_width, scale_height)
window_width = int(img.shape[1] * dimensions)
window_height = int(img.shape[0] * dimensions)
return window_width, window_height
Edited resizeWin()
def resizeWin(img, resize_factor=0.7):
"""
Get the system screen resolution and resize input image by a factor. Factor
must be in the range (0, 1].
"""
resize_factor = (1 - resize_factor) + 1
sys_w, sys_h = 1920/resize_factor, 1080/resize_factor
scale_width = sys_w / img.shape[1]
scale_height = sys_h / img.shape[0]
dimensions = min(scale_width, scale_height)
window_width = int(img.shape[1] * dimensions)
window_height = int(img.shape[0] * dimensions)
return window_width, window_height
In PebbleCounts.py, omitting the statement shown below that sets the matplotlib backend to TkAgg on Mac:
# use a different backend for matplotlib on MacOS
from sys import platform as sys_pf
if sys_pf == 'darwin':
import matplotlib
matplotlib.use('TkAgg')
Without this statement, matplotlib uses the MacOSX backend.
Thanks a lot of looking into this (I'm sure it took some time...)
I have had very similar issues in the past with compatibility between openCV, tkinter, and matplotlib. Most errors that have occurred for myself and other users have come at the window pop up stage with a "NSException".
Because this has been an ongoing issue (which I have previously changed bits of the code for), I will refrain from modifying and git-pushing a change to the code at this time. I fear that any change may break PebbleCounts on other machines, whereas nice comments like this can serve as a guide for other users to change a few import lines in the base code and try to get it working themselves.
Of course, as always, I'm available on GitHub or by email for trouble shooting.
I am trying to run PebbleCounts on a 2013 Mac Pro (Catalina 10.15.7). I followed the installation instructions for Mac verbatim from the manual, and found that both PebbleCounts.py and PebbleCountsAuto.py run smoothly up until the program needs to open a window, at which point Python crashes and throws the following exception:
I have reproduced everything on a 2019 MacBook Pro (Big Sur 11.2.1), and the errors are identical between the two machines.
I have found discussions of matplotlib backend issues on Mac, which generally advise using TkAgg (MTG/sms-tools#36). This solution is already implemented in PebbleCounts.py, and did not work for me. I am uncertain as to why Tk in general seems not to work in my pebblecounts Conda environment -- perhaps backwards incompatibility between Python 3.6 and Tk 8.6? Created as written in the manual, the pebblecounts environment uses Python 3.6.10 and Tk 8.6.10, both Conda’s default packages. These versions seem to be the only viable options, as PebbleCounts requires Python 3.6 for all necessary dependencies to work and Tk 8.5 has serious bugs that affect macOS (https://www.python.org/download/mac/tcltk/).
Solution
While I have not been able to get Tk to work in the pebblecounts environment, I was able to get PebbleCounts.py and PebbleCountsAuto.py running smoothly by making two edits:
Original resizeWin()
Edited resizeWin()
Without this statement, matplotlib uses the MacOSX backend.
The text was updated successfully, but these errors were encountered: