Исключение, созданное в режиме отладки PyCharm, но не в режиме выполнения (seaborn, matplotlib)

#python #numpy #matplotlib #pycharm #seaborn

Вопрос:

Я использую

  • PyCharm 2021.2.3 Издание сообщества
  • Интерпретатор Python 3.10.0
  • matplotlib 3.5.0
  • сиборн 0.11.2
  • numpy 1.21.4
  • панды 1.3.4
  • PySimpleGUI 4.55.1

Когда я запускаю следующий сценарий, он хорош в режиме выполнения, но в режиме отладки он создает исключение. Вот сценарий:

 import numpy as np import pandas as pd import PySimpleGUI as sg import seaborn as sns  from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg from matplotlib.figure import Figure   def init_data():  r1 = np.random.rand(5, 4)  columns = [f"var{i}" for i in range(1, 5)]  df = pd.DataFrame(r1, columns=columns)  df.insert(0, 'year', range(2021, 2026))  df.insert(1, 'scenario', 'test1')  ldf = pd.melt(df, id_vars=['year', 'scenario'], value_vars=columns, var_name='percentile', value_name='carbon')  return ldf   def draw_figure(canvas, figure):  figure_canvas_agg = FigureCanvasTkAgg(figure, canvas)  figure_canvas_agg.draw()  figure_canvas_agg.get_tk_widget().pack(side='top', fill='both', expand=1)  return figure_canvas_agg   # define the window layout layout = [[sg.Text('Plot test')],  [sg.Canvas(key='-CANVAS-')],  [sg.Button('Ok')]]  # create the form and show it without the plot window = sg.Window('Testing seaborn in PySimpleGUI', layout, finalize=True,  element_justification='center', font='Helvetica 18')  figure = Figure() ax = figure.subplots() sns.lineplot(x='year', y='carbon', hue='percentile', data=init_data(), ax=ax)  # add the plot to the window fig_canvas_agg = draw_figure(window['-CANVAS-'].TKCanvas, figure)  event, values = window.read()  window.close()  

А вот и дорожка:

 Traceback (most recent call last):  File "C:UsersdrlouAppDataLocalProgramsPythonPython310libsite-packagesnumpycoregetlimits.py", line 384, in __new__  dtype = numeric.dtype(dtype) TypeError: 'NoneType' object is not callable During handling of the above exception, another exception occurred: Traceback (most recent call last):  File "C:Program FilesJetBrainsPyCharm Community Edition 2021.2.3pluginspython-cehelperspydevpydevd.py", line 1483, in _exec  pydev_imports.execfile(file, globals, locals) # execute the script  File "C:Program FilesJetBrainsPyCharm Community Edition 2021.2.3pluginspython-cehelperspydev_pydev_imps_pydev_execfile.py", line 18, in execfile  exec(compile(contents "n", file, 'exec'), glob, loc)  File "D:/OneDrive/OneDrive - Louise Pryor amp; Co Ltd/Actuarial/Carbon/Carbon/seaborntest.py", line 39, in lt;modulegt;  sns.lineplot(x='year', y='carbon', hue='percentile', data=init_data(), ax=ax)  File "C:UsersdrlouAppDataLocalProgramsPythonPython310libsite-packagesseaborn_decorators.py", line 46, in inner_f  return f(**kwargs)  File "C:UsersdrlouAppDataLocalProgramsPythonPython310libsite-packagesseabornrelational.py", line 710, in lineplot  p.plot(ax, kwargs)  File "C:UsersdrlouAppDataLocalProgramsPythonPython310libsite-packagesseabornrelational.py", line 557, in plot  self._add_axis_labels(ax)  File "C:UsersdrlouAppDataLocalProgramsPythonPython310libsite-packagesseaborn_core.py", line 1194, in _add_axis_labels  x_visible = any(t.get_visible() for t in ax.get_xticklabels())  File "C:UsersdrlouAppDataLocalProgramsPythonPython310libsite-packagesmatplotlibaxes_base.py", line 75, in wrapper  return get_method(self)(*args, **kwargs)  File "C:UsersdrlouAppDataLocalProgramsPythonPython310libsite-packagesmatplotlibaxis.py", line 1249, in get_ticklabels  return self.get_majorticklabels()  File "C:UsersdrlouAppDataLocalProgramsPythonPython310libsite-packagesmatplotlibaxis.py", line 1201, in get_majorticklabels  ticks = self.get_major_ticks()  File "C:UsersdrlouAppDataLocalProgramsPythonPython310libsite-packagesmatplotlibaxis.py", line 1371, in get_major_ticks  numticks = len(self.get_majorticklocs())  File "C:UsersdrlouAppDataLocalProgramsPythonPython310libsite-packagesmatplotlibaxis.py", line 1277, in get_majorticklocs  return self.major.locator()  File "C:UsersdrlouAppDataLocalProgramsPythonPython310libsite-packagesmatplotlibticker.py", line 2113, in __call__  vmin, vmax = self.axis.get_view_interval()  File "C:UsersdrlouAppDataLocalProgramsPythonPython310libsite-packagesmatplotlibaxis.py", line 1987, in getter  return getattr(getattr(self.axes, lim_name), attr_name)  File "C:UsersdrlouAppDataLocalProgramsPythonPython310libsite-packagesmatplotlibaxes_base.py", line 781, in viewLim  self._unstale_viewLim()  File "C:UsersdrlouAppDataLocalProgramsPythonPython310libsite-packagesmatplotlibaxes_base.py", line 776, in _unstale_viewLim  self.autoscale_view(**{f"scale{name}": scale  File "C:UsersdrlouAppDataLocalProgramsPythonPython310libsite-packagesmatplotlibaxes_base.py", line 2932, in autoscale_view  handle_single_axis(  File "C:UsersdrlouAppDataLocalProgramsPythonPython310libsite-packagesmatplotlibaxes_base.py", line 2895, in handle_single_axis  x0, x1 = locator.nonsingular(x0, x1)  File "C:UsersdrlouAppDataLocalProgramsPythonPython310libsite-packagesmatplotlibticker.py", line 1654, in nonsingular  return mtransforms.nonsingular(v0, v1, expander=.05)  File "C:UsersdrlouAppDataLocalProgramsPythonPython310libsite-packagesmatplotlibtransforms.py", line 2880, in nonsingular  if maxabsvalue lt; (1e6 / tiny) * np.finfo(float).tiny:  File "C:UsersdrlouAppDataLocalProgramsPythonPython310libsite-packagesnumpycoregetlimits.py", line 387, in __new__  dtype = numeric.dtype(type(dtype)) TypeError: 'NoneType' object is not callable  

Кто-нибудь видел это раньше или у кого-нибудь есть какие-нибудь идеи?

Комментарии:

1. У меня та же проблема при вызове функции pandas dataframe.plot() и линейной регрессии scikit-learn().fit(X_train, y_train)…

2. То же самое, в Windows, с использованием 64-разрядной версии: — PyCharm 2021.3 — Python 3.10.1 — numpy 1.21.4 — pandas 1.3.5 — pandasgui 0.2.13 Код повтора: из импорта pandasgui показать импорт панд как pd df = pd.DataFrame() показать(df)

3. То же самое происходит и с Windows; используется 64-разрядная версия: PyCharm 2021.3 — Python 3.10.1 и matplotlib 3.5.1