在PyCharm的调试模式下,但在运行模式下没有出现异常(seaborn、matplotlib)。

9

我正在使用:

  • PyCharm 2021.2.3 社区版
  • Python 解释器 3.10.0
  • matplotlib 3.5.0
  • seaborn 0.11.2
  • numpy 1.21.4
  • pandas 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:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\numpy\core\getlimits.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 Files\JetBrains\PyCharm Community Edition 2021.2.3\plugins\python-ce\helpers\pydev\pydevd.py", line 1483, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.2.3\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "D:/OneDrive/OneDrive - Louise Pryor & Co Ltd/Actuarial/Carbon/Carbon/seaborntest.py", line 39, in <module>
    sns.lineplot(x='year', y='carbon', hue='percentile', data=init_data(), ax=ax)
  File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\seaborn\_decorators.py", line 46, in inner_f
    return f(**kwargs)
  File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\seaborn\relational.py", line 710, in lineplot
    p.plot(ax, kwargs)
  File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\seaborn\relational.py", line 557, in plot
    self._add_axis_labels(ax)
  File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\seaborn\_core.py", line 1194, in _add_axis_labels
    x_visible = any(t.get_visible() for t in ax.get_xticklabels())
  File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\axes\_base.py", line 75, in wrapper
    return get_method(self)(*args, **kwargs)
  File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\axis.py", line 1249, in get_ticklabels
    return self.get_majorticklabels()
  File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\axis.py", line 1201, in get_majorticklabels
    ticks = self.get_major_ticks()
  File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\axis.py", line 1371, in get_major_ticks
    numticks = len(self.get_majorticklocs())
  File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\axis.py", line 1277, in get_majorticklocs
    return self.major.locator()
  File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\ticker.py", line 2113, in __call__
    vmin, vmax = self.axis.get_view_interval()
  File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\axis.py", line 1987, in getter
    return getattr(getattr(self.axes, lim_name), attr_name)
  File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\axes\_base.py", line 781, in viewLim
    self._unstale_viewLim()
  File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\axes\_base.py", line 776, in _unstale_viewLim
    self.autoscale_view(**{f"scale{name}": scale
  File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\axes\_base.py", line 2932, in autoscale_view
    handle_single_axis(
  File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\axes\_base.py", line 2895, in handle_single_axis
    x0, x1 = locator.nonsingular(x0, x1)
  File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\ticker.py", line 1654, in nonsingular
    return mtransforms.nonsingular(v0, v1, expander=.05)
  File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\matplotlib\transforms.py", line 2880, in nonsingular
    if maxabsvalue < (1e6 / tiny) * np.finfo(float).tiny:
  File "C:\Users\drlou\AppData\Local\Programs\Python\Python310\lib\site-packages\numpy\core\getlimits.py", line 387, in __new__
    dtype = numeric.dtype(type(dtype))
TypeError: 'NoneType' object is not callable

有人以前看过这个或者有什么想法吗?

2
当我调用pandas dataframe.plot()函数和scikit-learn的LinearRegression().fit(X_train, y_train)时,我遇到了相同的问题... - translater
相同的环境,在Windows上,使用64位:
  • PyCharm 2021.3
  • Python 3.10.1
  • numpy 1.21.4
  • pandas 1.3.5
  • pandasgui 0.2.13
复现代码: from pandasgui import show import pandas as pd df = pd.DataFrame() show(df)
- Chad Kennedy
在Windows上遇到相同的问题;使用64位:PyCharm 2021.3 - Python 3.10.1和matplotlib 3.5.1。 - Holdsworth
同样的问题,由'from scipy import optimize'触发,Win 10 64位,PyCharm 2021.3,Python 3.10,pandas 1.3.4,numpy 1.21.4(还升级到了1.22.1)。 - rm957377
在VSCode上调试Python v3.10文件时,与以往一样。 - infinity
显示剩余2条评论
2个回答

5

在将我的Python版本从3.10更改为3.9.5之前,我遇到了相同的问题。


你的回答可以通过提供更多支持信息来改进。请编辑以添加进一步的细节,例如引用或文档,以便他人可以确认你的答案是正确的。您可以在帮助中心中找到有关如何编写良好答案的更多信息。 - Community
我最终也采用了同样的方法,这对我非常有效。 - infinity
我把我的 Python 版本从 3.10 改为了 3.9.5。这对我非常有帮助,谢谢。 - user3226704

-1

这是在pyCharm 2022.1.1,python 3.10.4,scipy=1.8.0,numpy=1.22.3,pandas=1.4.1下进行调试的丑陋技巧。

AK对于numpy与pandas/scipy np.core.numeric.dtype调试问题的不成熟处理

如果sys.gettrace(): np.core.numeric.dtype = np.dtype


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接