1、int() argument must be a string, a bytes-like object or a number, not ‘KeyboardModifier‘
说明
根据Python官网,Python3.7还支持WIN7。
项目对应的requirements.txt为:
cycler==0.11.0
fonttools==4.38.0
kiwisolver==1.4.4
matplotlib==3.5.3
Nuitka==1.5.7
numpy==1.21.6
ordered-set==4.1.0
packaging==23.1
Pillow==9.5.0
pyparsing==3.0.9
PySide2==5.15.2.1
python-dateutil==2.8.2
shiboken2==5.15.2.1
six==1.16.0
typing-extensions==4.5.0
zstandard==0.21.0
项目对应的nuitka命令为:
nuitka --standalone --output-dir=out --plugin-enable=pyside2 --nofollow-import-to=tkinter --windows-disable-console
解决方案
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
报错主要是PySide6与matplotlib之间接口兼容性的问题。报错位置代码
_MODIFIER_KEYS = [
(_to_int(getattr(_enum("QtCore.Qt.KeyboardModifier"), mod)),
_to_int(getattr(_enum("QtCore.Qt.Key"), key)))
for mod, key in [
("ControlModifier", "Key_Control"),
("AltModifier", "Key_Alt"),
("ShiftModifier", "Key_Shift"),
("MetaModifier", "Key_Meta"),
]
]
根据gpt,
这段代码是一个用于将 Qt 的键盘修饰符和按键转换为整数类型的列表。具体来说,代码中定义了一个名为 _MODIFIER_KEYS 的列表,其中包含了 4 个二元组,每个二元组分别表示一个修饰符和对应的按键,且每个元素都是整数类型。
这段代码通过调用 getattr() 方法获取了 PySide6.QtCore.Qt.KeyboardModifier 和 PySide6.QtCore.Qt.Key 枚举类对应的属性,使用 _to_int() 函数将枚举值转换为整数类型,并最终构造成二元组的形式存放在 _MODIFIER_KEYS 列表中。
这个列表可以用于接收 Qt 的快捷键事件后进行处理,比如判断按下的键是否为某个快捷键等。
需要注意的是,这里使用了 _enum() 函数获取枚举类,但代码中未给出该函数的实现,可能是在其他地方定义的函数,因此如果要运行这段代码,还需要先确保 _enum() 函数已经定义并导入。
根据matplotlib官方issues,解决方案是,
mpl 升级到 >=3.6.2 或将 pyside 降级到 <6.4.0
Python3.7下matplotlib,最高支持3.5,因而使用pyside==6.3.0,此时需要注意NavigationToolbar2QT需要canvas,parent两个参数。
class NavigationToolbar2QT(NavigationToolbar2, QtWidgets.QToolBar):
.......
def __init__(self, canvas, parent, coordinates=True):
.......
2、Pandas Excel file format cannot be determined, you must specify an engine manually.
说明
Pandas读取Excel报错Excel file format cannot be determined, you must specify an engine manually.
pd.read_excel方法本身是支持多种引擎的,包括"xlrd", “openpyxl”, “odf”, “pyxlsb”,更换引擎后依然失效!
Debug
我们直接用可以直接用open with打开源文件
with open(ipath, 'r', encoding='utf-8') as f:
print(f.read())
神奇的一幕发生了,
有的文件名义上是Excel,其实内心是个Html!文章来源:https://www.toymoban.com/news/detail-528006.html
解决办法
使用pd.read_html方法文章来源地址https://www.toymoban.com/news/detail-528006.html
df = pd.read_html(ipath, header=2)[0]
到了这里,关于【Python】Pandas Excel file format cannot be determined, you must specify an engine manually.报错【已解决】的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!