最近一些Python 问题小结

23 阅读1分钟

一、numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject

The reason is that pandas defines its numpy dependency freely as "anything newer than certain version of numpy". The problem occured, when numpy==2.0.0 has been released on June 16th 2024, because it is no longer compatible with your pandas version.

The solution is to pin down the numpy version to any before the 2.0.0. Today it could be (this is the most recent numpy 1 release):

numpy==1.26.4

To be added in your requirements or to the pip command you use (but together with installing pandas).

Nowadays pip is very flexible and can handle the issue flawesly. You just need to ask it to install both pandas and numpy of given versions in the same pip install invocation.

二、 python报错 TypeError: bad operand type for unary +: 'str' 的解决办法

在Stack Overflow上找到了一种解释,链接如下:stackoverflow.com/questions/2…

大意就是这个没有把一元运算符做字符串,可以通过给式子加上括号来解决